Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
diffoscope
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Reproducible Builds
diffoscope
Commits
cf4a4c3b
Verified
Commit
cf4a4c3b
authored
8 years ago
by
Mattia Rizzolo
Browse files
Options
Downloads
Patches
Plain Diff
tests: rewrite tool_older_than() into skip_unless_tool_is_older_than()
parent
3b98ffeb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
tests/comparators/test_rlib.py
+7
-3
7 additions, 3 deletions
tests/comparators/test_rlib.py
tests/comparators/test_utils.py
+12
-1
12 additions, 1 deletion
tests/comparators/test_utils.py
tests/comparators/utils.py
+11
-8
11 additions, 8 deletions
tests/comparators/utils.py
with
30 additions
and
12 deletions
tests/comparators/test_rlib.py
+
7
−
3
View file @
cf4a4c3b
...
...
@@ -19,16 +19,20 @@
# along with diffoscope. If not, see <http://www.gnu.org/licenses/>.
import
pytest
import
subprocess
from
diffoscope.comparators.ar
import
ArFile
from
diffoscope.comparators.utils
import
diff_ignore_line_numbers
from
utils
import
skip_unless_tools_exist
,
tool_older_than
,
data
,
\
load_fixture
,
assert_non_existing
from
utils
import
skip_unless_tools_exist
,
skip_unless_
tool_
is_
older_than
,
\
data
,
load_fixture
,
assert_non_existing
rlib1
=
load_fixture
(
data
(
'
test1.rlib
'
))
rlib2
=
load_fixture
(
data
(
'
test2.rlib
'
))
def
llvm_version
():
return
subprocess
.
check_output
([
'
llvm-config
'
,
'
--version
'
]).
decode
(
"
utf-8
"
).
strip
()
def
test_identification
(
rlib1
):
assert
isinstance
(
rlib1
,
ArFile
)
...
...
@@ -60,7 +64,7 @@ def test_item2_rust_metadata_bin(differences):
assert
differences
[
2
].
source2
==
'
rust.metadata.bin
'
@skip_unless_tools_exist
(
'
llvm-dis
'
)
@
pytest.mark.skipif
(
tool_older_than
(
[
'
llvm-config
'
,
'
--
version
'
]
,
'
3.8
'
)
,
reason
=
'
llvm version too low
'
)
@
skip_unless_
tool_
is_
older_than
(
'
llvm-config
'
,
llvm_
version
,
'
3.8
'
)
def
test_item3_deflate_llvm_bitcode
(
differences
):
assert
differences
[
3
].
source1
==
'
alloc_system-d16b8f0e.0.bytecode.deflate
'
assert
differences
[
3
].
source2
==
'
alloc_system-d16b8f0e.0.bytecode.deflate
'
...
...
This diff is collapsed.
Click to expand it.
tests/comparators/test_utils.py
+
12
−
1
View file @
cf4a4c3b
...
...
@@ -24,7 +24,8 @@ from diffoscope.config import Config
from
diffoscope.difference
import
Difference
from
diffoscope.comparators.utils
import
Command
from
utils
import
tools_missing
,
skip_unless_tools_exist
,
data
,
load_fixture
from
utils
import
tools_missing
,
skip_unless_tools_exist
,
data
,
load_fixture
,
\
skip_unless_tool_is_older_than
try
:
import
tlsh
# noqa
...
...
@@ -50,6 +51,16 @@ def test_skip_unless_tools_exist_empty():
def
test_skip_unless_tools_exist_missing
():
pytest
.
xfail
(
"
Test should always be skipped
"
)
def
skip_unless_tool_is_older_than
():
func
=
skip_unless_tool_is_older_than
assert
func
(
'
/missing
'
,
1
,
1
).
name
is
'
skip
'
# pytest.skipif().args[0] contains the evaluated statement
assert
func
(
'
cat
'
,
1
,
1
).
args
[
0
]
is
False
assert
func
(
'
cat
'
,
1
,
'
1.2d.45+b8
'
).
args
[
0
]
is
True
def
version
():
return
'
4.3-git
'
assert
func
(
'
cat
'
,
version
,
'
4.3
'
).
args
[
0
]
is
False
@pytest.mark.skipif
(
miss_tlsh
,
reason
=
'
tlsh is missing
'
)
def
test_fuzzy_matching
(
fuzzy_tar1
,
fuzzy_tar2
):
differences
=
fuzzy_tar1
.
compare
(
fuzzy_tar2
).
details
...
...
This diff is collapsed.
Click to expand it.
tests/comparators/utils.py
+
11
−
8
View file @
cf4a4c3b
...
...
@@ -20,10 +20,9 @@
import
os
import
pytest
import
diffoscope
import
subprocess
from
distutils.spawn
import
find_executable
from
distutils.version
import
Strict
Version
from
distutils.version
import
Loose
Version
from
diffoscope.config
import
Config
from
diffoscope.comparators
import
specialize
...
...
@@ -45,6 +44,16 @@ def skip_unless_tools_exist(*required):
reason
=
"
requires {}
"
.
format
(
"
and
"
.
join
(
required
)),
)
def
skip_unless_tool_is_older_than
(
tool
,
actual_ver
,
min_ver
,
vcls
=
LooseVersion
):
if
tools_missing
(
tool
):
return
pytest
.
mark
.
skip
(
reason
=
"
requires {}
"
.
format
(
tool
))
if
callable
(
actual_ver
):
actual_ver
=
actual_ver
()
return
pytest
.
mark
.
skipif
(
vcls
(
str
(
actual_ver
))
<
vcls
(
str
(
min_ver
)),
reason
=
"
requires {} >= {}
"
.
format
(
tool
,
min_ver
)
)
def
load_fixture
(
filename
):
return
pytest
.
fixture
(
lambda
:
specialize
(
FilesystemFile
(
filename
))
...
...
@@ -57,12 +66,6 @@ def data(filename):
filename
,
)
def
tool_older_than
(
cmdline
,
min_ver
,
vcls
=
StrictVersion
):
if
find_executable
(
cmdline
[
0
])
is
None
:
return
True
actual_ver
=
subprocess
.
check_output
(
cmdline
).
decode
(
"
utf-8
"
).
strip
()
return
vcls
(
actual_ver
)
<
vcls
(
min_ver
)
def
assert_non_existing
(
monkeypatch
,
fixture
,
has_null_source
=
True
,
has_details
=
True
):
monkeypatch
.
setattr
(
Config
.
general
,
'
new_file
'
,
True
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment