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:
Ana Maria Martinez Gomez
2021-03-15 18:12:35 +01:00
parent 058b61b10c
commit c0d6468347
6 changed files with 14 additions and 36 deletions

View File

@@ -52,8 +52,6 @@ jobs:
python-version: [3.6, 3.9] python-version: [3.6, 3.9]
include: include:
# on Ubuntu run these as well # on Ubuntu run these as well
- os: ubuntu-20.04
python-version: 2.7
- os: ubuntu-20.04 - os: ubuntu-20.04
python-version: 3.7 python-version: 3.7
- os: ubuntu-20.04 - os: ubuntu-20.04

View File

@@ -8,7 +8,6 @@
# See the License for the specific language governing permissions and limitations under the License. # See the License for the specific language governing permissions and limitations under the License.
import os import os
import sys
import os.path import os.path
import binascii import binascii
import contextlib import contextlib

View File

@@ -5,7 +5,6 @@
# Unless required by applicable law or agreed to in writing, software distributed under the License # 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. # 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. # See the License for the specific language governing permissions and limitations under the License.
import sys
import textwrap import textwrap
import pytest import pytest
@@ -174,7 +173,6 @@ def test_serialize_features():
roundtrip_feature(capa.features.file.Import("#11")) 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): def test_freeze_sample(tmpdir, z9324d_extractor):
# tmpdir fixture handles cleanup # tmpdir fixture handles cleanup
o = tmpdir.mkdir("capa").join("test.frz").strpath 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 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): def test_freeze_load_sample(tmpdir, z9324d_extractor):
o = tmpdir.mkdir("capa").join("test.frz") o = tmpdir.mkdir("capa").join("test.frz")

View File

@@ -12,8 +12,6 @@ from capa.features.extractors import helpers
def test_all_zeros(): def test_all_zeros():
# Python 2: <str>
# Python 3: <bytes>
a = b"\x00\x00\x00\x00" a = b"\x00\x00\x00\x00"
b = codecs.decode("00000000", "hex") b = codecs.decode("00000000", "hex")
c = b"\x01\x00\x00\x00" c = b"\x01\x00\x00\x00"

View File

@@ -6,7 +6,6 @@
# Unless required by applicable law or agreed to in writing, software distributed under the License # 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. # 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. # See the License for the specific language governing permissions and limitations under the License.
import sys
import json import json
import textwrap import textwrap
@@ -58,10 +57,6 @@ def test_main_single_rule(z9324d_extractor, tmpdir):
def test_main_non_ascii_filename(pingtaest_extractor, tmpdir, capsys): 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 # here we print a string with unicode characters in it
# (specifically, a byte string with utf-8 bytes in it, see file encoding) # (specifically, a byte string with utf-8 bytes in it, see file encoding)
assert capa.main.main(["-q", pingtaest_extractor.path]) == 0 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() std = capsys.readouterr()
# but here, we have to use a unicode instance, # but here, we have to use a unicode instance,
# because capsys has decoded the output for us. # because capsys has decoded the output for us.
if sys.version_info >= (3, 0): assert pingtaest_extractor.path in std.out
assert pingtaest_extractor.path in std.out
else:
assert pingtaest_extractor.path.decode("utf-8") in std.out
def test_main_non_ascii_filename_nonexistent(tmpdir, caplog): def test_main_non_ascii_filename_nonexistent(tmpdir, caplog):
NON_ASCII_FILENAME = "täst_not_there.exe" NON_ASCII_FILENAME = "täst_not_there.exe"
assert capa.main.main(["-q", NON_ASCII_FILENAME]) == -1 assert capa.main.main(["-q", NON_ASCII_FILENAME]) == -1
if sys.version_info >= (3, 0): assert NON_ASCII_FILENAME in caplog.text
assert NON_ASCII_FILENAME in caplog.text
else:
assert NON_ASCII_FILENAME.decode("utf-8") in caplog.text
def test_main_shellcode(z499c2_extractor): 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 # It tests main works with different backends
def test_backend_option(capsys): def test_backend_option(capsys):
if sys.version_info > (3, 0): path = get_data_path_by_name("pma16-01")
path = get_data_path_by_name("pma16-01") assert capa.main.main([path, "-j", "-b", capa.main.BACKEND_VIV]) == 0
assert capa.main.main([path, "-j", "-b", capa.main.BACKEND_VIV]) == 0 std = capsys.readouterr()
std = capsys.readouterr() std_json = json.loads(std.out)
std_json = json.loads(std.out) assert std_json["meta"]["analysis"]["extractor"] == "VivisectFeatureExtractor"
assert std_json["meta"]["analysis"]["extractor"] == "VivisectFeatureExtractor" assert len(std_json["rules"]) > 0
assert len(std_json["rules"]) > 0
assert capa.main.main([path, "-j", "-b", capa.main.BACKEND_SMDA]) == 0 assert capa.main.main([path, "-j", "-b", capa.main.BACKEND_SMDA]) == 0
std = capsys.readouterr() std = capsys.readouterr()
std_json = json.loads(std.out) std_json = json.loads(std.out)
assert std_json["meta"]["analysis"]["extractor"] == "SmdaFeatureExtractor" assert std_json["meta"]["analysis"]["extractor"] == "SmdaFeatureExtractor"
assert len(std_json["rules"]) > 0 assert len(std_json["rules"]) > 0

View File

@@ -15,7 +15,6 @@ from fixtures import *
FEATURE_PRESENCE_TESTS, FEATURE_PRESENCE_TESTS,
indirect=["sample", "scope"], 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") @pytest.mark.xfail(sys.platform == "win32", reason="SMDA bug: https://github.com/danielplohmann/smda/issues/20")
def test_smda_features(sample, scope, feature, expected): def test_smda_features(sample, scope, feature, expected):
do_test_feature_presence(get_smda_extractor, 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"], indirect=["sample", "scope"],
) )
def test_smda_feature_counts(sample, scope, feature, expected): 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)