4444logger = logging .getLogger (__name__ )
4545CD = Path (__file__ ).resolve ().parent
4646FIXTURE_MANIFEST_DIR = CD / "fixtures" / "features"
47- DOTNET_DIR = CD / "data" / "dotnet"
48- DNFILE_TESTFILES = DOTNET_DIR / "dnfile-testfiles"
47+ DNFILE_TESTFILES = CD / "data" / "dotnet" / "dnfile-testfiles"
4948
5049
5150def parse_feature_string (s : str ) -> Feature | ceng .Range | ceng .Statement :
@@ -366,44 +365,6 @@ def run_feature_fixture(
366365 assert actual == fixture .expected , msg
367366
368367
369- @contextlib .contextmanager
370- def xfail (condition , reason : str = "" ):
371- """
372- context manager that wraps a block that is expected to fail in some cases.
373- when it does fail (and is expected), then mark this as pytest.xfail.
374- if its unexpected, raise an exception, so the test fails.
375-
376- example::
377-
378- # this test:
379- # - passes on Linux if foo() works
380- # - fails on Linux if foo() fails
381- # - xfails on Windows if foo() fails
382- # - fails on Windows if foo() works
383- with xfail(sys.platform == "win32", reason="doesn't work on Windows"):
384- foo()
385- """
386- try :
387- # do the block
388- yield
389- except Exception :
390- if condition :
391- # we expected the test to fail, so raise and register this via pytest
392- pytest .xfail (reason or "" )
393- else :
394- # we don't expect an exception, so the test should fail
395- raise
396- else :
397- if not condition :
398- # here we expect the block to run successfully,
399- # and we've received no exception,
400- # so this is good
401- pass
402- else :
403- # we expected an exception, but didn't find one. that's an error.
404- raise RuntimeError ("expected to fail, but didn't" )
405-
406-
407368def extract_global_features (extractor ):
408369 features = collections .defaultdict (set )
409370 for feature , va in extractor .extract_global_features ():
@@ -671,11 +632,6 @@ def inner_process(extractor):
671632 raise ValueError ("unexpected scope fixture" )
672633
673634
674- @pytest .fixture
675- def scope (request ):
676- return resolve_scope (request .param )
677-
678-
679635def make_test_id (values ):
680636 return "-" .join (map (str , values ))
681637
@@ -692,58 +648,7 @@ def parametrize(params, values, **kwargs):
692648 return pytest .mark .parametrize (params , values , ids = ids , ** kwargs )
693649
694650
695- def get_result_doc (path : Path ):
696- return capa .render .result_document .ResultDocument .from_file (path )
697-
698-
699- @pytest .fixture
700- def pma0101_rd ():
701- # python -m capa.main tests/data/Practical\ Malware\ Analysis\ Lab\ 01-01.dll_ --json > tests/data/rd/Practical\ Malware\ Analysis\ Lab\ 01-01.dll_.json
702- return get_result_doc (CD / "data" / "rd" / "Practical Malware Analysis Lab 01-01.dll_.json" )
703-
704-
705- @pytest .fixture
706- def dotnet_1c444e_rd ():
707- # .NET sample
708- # python -m capa.main tests/data/dotnet/1c444ebeba24dcba8628b7dfe5fec7c6.exe_ --json > tests/data/rd/1c444ebeba24dcba8628b7dfe5fec7c6.exe_.json
709- return get_result_doc (CD / "data" / "rd" / "1c444ebeba24dcba8628b7dfe5fec7c6.exe_.json" )
710-
711-
712- @pytest .fixture
713- def a3f3bbc_rd ():
714- # python -m capa.main tests/data/3f3bbcf8fd90bdcdcdc5494314ed4225.exe_ --json > tests/data/rd/3f3bbcf8fd90bdcdcdc5494314ed4225.exe_.json
715- return get_result_doc (CD / "data" / "rd" / "3f3bbcf8fd90bdcdcdc5494314ed4225.exe_.json" )
716-
717-
718- @pytest .fixture
719- def al_khaserx86_rd ():
720- # python -m capa.main tests/data/al-khaser_x86.exe_ --json > tests/data/rd/al-khaser_x86.exe_.json
721- return get_result_doc (CD / "data" / "rd" / "al-khaser_x86.exe_.json" )
722-
723-
724- @pytest .fixture
725- def al_khaserx64_rd ():
726- # python -m capa.main tests/data/al-khaser_x64.exe_ --json > tests/data/rd/al-khaser_x64.exe_.json
727- return get_result_doc (CD / "data" / "rd" / "al-khaser_x64.exe_.json" )
728-
729-
730- @pytest .fixture
731- def a076114_rd ():
732- # python -m capa.main tests/data/0761142efbda6c4b1e801223de723578.dll_ --json > tests/data/rd/0761142efbda6c4b1e801223de723578.dll_.json
733- return get_result_doc (CD / "data" / "rd" / "0761142efbda6c4b1e801223de723578.dll_.json" )
734-
735-
736- @pytest .fixture
737- def dynamic_a0000a6_rd ():
738- # python -m capa.main tests/data/dynamic/cape/v2.2/0000a65749f5902c4d82ffa701198038f0b4870b00a27cfca109f8f933476d82.json --json > tests/data/rd/0000a65749f5902c4d82ffa701198038f0b4870b00a27cfca109f8f933476d82.json
739- # gzip tests/data/rd/0000a65749f5902c4d82ffa701198038f0b4870b00a27cfca109f8f933476d82.json
740- return get_result_doc (
741- CD / "data" / "rd" / "0000a65749f5902c4d82ffa701198038f0b4870b00a27cfca109f8f933476d82.json.gz"
742- )
743-
744-
745651PMA1601 = CD / "data" / "Practical Malware Analysis Lab 16-01.exe_"
746- z9324 = CD / "data" / "9324d1a8ae37a36ae560c37448c9705a.exe_"
747652
748653
749654# used by test_viv_features
@@ -786,7 +691,7 @@ def get_viv_extractor(path: Path):
786691
787692@pytest .fixture
788693def z9324d_extractor ():
789- return get_viv_extractor (z9324 )
694+ return get_viv_extractor (CD / "data" / "9324d1a8ae37a36ae560c37448c9705a.exe_" )
790695
791696
792697@pytest .fixture
0 commit comments