mirror of
https://github.com/mandiant/capa.git
synced 2025-12-12 15:49:46 -08:00
py3: Remove Python 2 tests
Tests don't need to support Python 2 any longer. Do not run tests with Python 2.
This commit is contained in:
2
.github/workflows/tests.yml
vendored
2
.github/workflows/tests.yml
vendored
@@ -52,8 +52,6 @@ jobs:
|
||||
python-version: [3.6, 3.9]
|
||||
include:
|
||||
# on Ubuntu run these as well
|
||||
- os: ubuntu-20.04
|
||||
python-version: 2.7
|
||||
- os: ubuntu-20.04
|
||||
python-version: 3.7
|
||||
- os: ubuntu-20.04
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
# See the License for the specific language governing permissions and limitations under the License.
|
||||
|
||||
import os
|
||||
import sys
|
||||
import os.path
|
||||
import binascii
|
||||
import contextlib
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and limitations under the License.
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
import pytest
|
||||
@@ -174,7 +173,6 @@ def test_serialize_features():
|
||||
roundtrip_feature(capa.features.file.Import("#11"))
|
||||
|
||||
|
||||
@pytest.mark.xfail(sys.version_info >= (3, 0), reason="vivsect only works on py2")
|
||||
def test_freeze_sample(tmpdir, z9324d_extractor):
|
||||
# tmpdir fixture handles cleanup
|
||||
o = tmpdir.mkdir("capa").join("test.frz").strpath
|
||||
@@ -182,7 +180,6 @@ def test_freeze_sample(tmpdir, z9324d_extractor):
|
||||
assert capa.features.freeze.main([path, o, "-v"]) == 0
|
||||
|
||||
|
||||
@pytest.mark.xfail(sys.version_info >= (3, 0), reason="vivsect only works on py2")
|
||||
def test_freeze_load_sample(tmpdir, z9324d_extractor):
|
||||
o = tmpdir.mkdir("capa").join("test.frz")
|
||||
|
||||
|
||||
@@ -12,8 +12,6 @@ from capa.features.extractors import helpers
|
||||
|
||||
|
||||
def test_all_zeros():
|
||||
# Python 2: <str>
|
||||
# Python 3: <bytes>
|
||||
a = b"\x00\x00\x00\x00"
|
||||
b = codecs.decode("00000000", "hex")
|
||||
c = b"\x01\x00\x00\x00"
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
# Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and limitations under the License.
|
||||
import sys
|
||||
import json
|
||||
import textwrap
|
||||
|
||||
@@ -58,10 +57,6 @@ def test_main_single_rule(z9324d_extractor, tmpdir):
|
||||
|
||||
|
||||
def test_main_non_ascii_filename(pingtaest_extractor, tmpdir, capsys):
|
||||
# on py2.7, need to be careful about str (which can hold bytes)
|
||||
# vs unicode (which is only unicode characters).
|
||||
# on py3, this should not be needed.
|
||||
#
|
||||
# here we print a string with unicode characters in it
|
||||
# (specifically, a byte string with utf-8 bytes in it, see file encoding)
|
||||
assert capa.main.main(["-q", pingtaest_extractor.path]) == 0
|
||||
@@ -69,20 +64,14 @@ def test_main_non_ascii_filename(pingtaest_extractor, tmpdir, capsys):
|
||||
std = capsys.readouterr()
|
||||
# but here, we have to use a unicode instance,
|
||||
# because capsys has decoded the output for us.
|
||||
if sys.version_info >= (3, 0):
|
||||
assert pingtaest_extractor.path in std.out
|
||||
else:
|
||||
assert pingtaest_extractor.path.decode("utf-8") in std.out
|
||||
assert pingtaest_extractor.path in std.out
|
||||
|
||||
|
||||
def test_main_non_ascii_filename_nonexistent(tmpdir, caplog):
|
||||
NON_ASCII_FILENAME = "täst_not_there.exe"
|
||||
assert capa.main.main(["-q", NON_ASCII_FILENAME]) == -1
|
||||
|
||||
if sys.version_info >= (3, 0):
|
||||
assert NON_ASCII_FILENAME in caplog.text
|
||||
else:
|
||||
assert NON_ASCII_FILENAME.decode("utf-8") in caplog.text
|
||||
assert NON_ASCII_FILENAME in caplog.text
|
||||
|
||||
|
||||
def test_main_shellcode(z499c2_extractor):
|
||||
@@ -370,16 +359,15 @@ def test_not_render_rules_also_matched(z9324d_extractor, capsys):
|
||||
|
||||
# It tests main works with different backends
|
||||
def test_backend_option(capsys):
|
||||
if sys.version_info > (3, 0):
|
||||
path = get_data_path_by_name("pma16-01")
|
||||
assert capa.main.main([path, "-j", "-b", capa.main.BACKEND_VIV]) == 0
|
||||
std = capsys.readouterr()
|
||||
std_json = json.loads(std.out)
|
||||
assert std_json["meta"]["analysis"]["extractor"] == "VivisectFeatureExtractor"
|
||||
assert len(std_json["rules"]) > 0
|
||||
path = get_data_path_by_name("pma16-01")
|
||||
assert capa.main.main([path, "-j", "-b", capa.main.BACKEND_VIV]) == 0
|
||||
std = capsys.readouterr()
|
||||
std_json = json.loads(std.out)
|
||||
assert std_json["meta"]["analysis"]["extractor"] == "VivisectFeatureExtractor"
|
||||
assert len(std_json["rules"]) > 0
|
||||
|
||||
assert capa.main.main([path, "-j", "-b", capa.main.BACKEND_SMDA]) == 0
|
||||
std = capsys.readouterr()
|
||||
std_json = json.loads(std.out)
|
||||
assert std_json["meta"]["analysis"]["extractor"] == "SmdaFeatureExtractor"
|
||||
assert len(std_json["rules"]) > 0
|
||||
assert capa.main.main([path, "-j", "-b", capa.main.BACKEND_SMDA]) == 0
|
||||
std = capsys.readouterr()
|
||||
std_json = json.loads(std.out)
|
||||
assert std_json["meta"]["analysis"]["extractor"] == "SmdaFeatureExtractor"
|
||||
assert len(std_json["rules"]) > 0
|
||||
|
||||
@@ -15,7 +15,6 @@ from fixtures import *
|
||||
FEATURE_PRESENCE_TESTS,
|
||||
indirect=["sample", "scope"],
|
||||
)
|
||||
@pytest.mark.xfail(sys.version_info < (3, 0), reason="SMDA only works on py3")
|
||||
@pytest.mark.xfail(sys.platform == "win32", reason="SMDA bug: https://github.com/danielplohmann/smda/issues/20")
|
||||
def test_smda_features(sample, scope, feature, expected):
|
||||
do_test_feature_presence(get_smda_extractor, sample, scope, feature, expected)
|
||||
@@ -27,5 +26,4 @@ def test_smda_features(sample, scope, feature, expected):
|
||||
indirect=["sample", "scope"],
|
||||
)
|
||||
def test_smda_feature_counts(sample, scope, feature, expected):
|
||||
with xfail(sys.version_info < (3, 0), reason="SMDA only works on py3"):
|
||||
do_test_feature_count(get_smda_extractor, sample, scope, feature, expected)
|
||||
do_test_feature_count(get_smda_extractor, sample, scope, feature, expected)
|
||||
|
||||
Reference in New Issue
Block a user