diff --git a/.gitignore b/.gitignore --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ build dist version.txt +.tox diff --git a/requirements-test.txt b/requirements-test.txt --- a/requirements-test.txt +++ b/requirements-test.txt @@ -1 +1 @@ -nose +pytest diff --git a/swh/model/tests/fields/test_compound.py b/swh/model/tests/fields/test_compound.py --- a/swh/model/tests/fields/test_compound.py +++ b/swh/model/tests/fields/test_compound.py @@ -168,17 +168,17 @@ exc = cm.exception self.assertIsInstance(str(exc), str) - self.assertEquals(set(exc.error_dict.keys()), {NON_FIELD_ERRORS}) + self.assertEqual(set(exc.error_dict.keys()), {NON_FIELD_ERRORS}) non_field_errors = exc.error_dict[NON_FIELD_ERRORS] self.assertIsInstance(non_field_errors, list) - self.assertEquals(len(non_field_errors), 1) + self.assertEqual(len(non_field_errors), 1) nested = non_field_errors[0] self.assertIsInstance(nested, ValidationError) - self.assertEquals(nested.code, 'model-validation-failed') - self.assertEquals(nested.params['model'], self.test_model) - self.assertEquals(nested.params['validator'], 'validate_never') + self.assertEqual(nested.code, 'model-validation-failed') + self.assertEqual(nested.params['model'], self.test_model) + self.assertEqual(nested.params['validator'], 'validate_never') def test_validate_against_schema_field_error(self): with self.assertRaises(ValidationError) as cm: @@ -192,15 +192,15 @@ exc = cm.exception self.assertIsInstance(str(exc), str) - self.assertEquals(set(exc.error_dict.keys()), {'str'}) + self.assertEqual(set(exc.error_dict.keys()), {'str'}) str_errors = exc.error_dict['str'] self.assertIsInstance(str_errors, list) - self.assertEquals(len(str_errors), 1) + self.assertEqual(len(str_errors), 1) nested = str_errors[0] self.assertIsInstance(nested, ValidationError) - self.assertEquals(nested.code, 'unexpected-type') + self.assertEqual(nested.code, 'unexpected-type') def test_validate_against_schema_field_failed(self): with self.assertRaises(ValidationError) as cm: @@ -215,14 +215,14 @@ exc = cm.exception self.assertIsInstance(str(exc), str) - self.assertEquals(set(exc.error_dict.keys()), {'int'}) + self.assertEqual(set(exc.error_dict.keys()), {'int'}) int_errors = exc.error_dict['int'] self.assertIsInstance(int_errors, list) - self.assertEquals(len(int_errors), 1) + self.assertEqual(len(int_errors), 1) nested = int_errors[0] self.assertIsInstance(nested, ValidationError) - self.assertEquals(nested.code, 'field-validation-failed') - self.assertEquals(nested.params['validator'], 'validate_never') - self.assertEquals(nested.params['field'], 'int') + self.assertEqual(nested.code, 'field-validation-failed') + self.assertEqual(nested.params['validator'], 'validate_never') + self.assertEqual(nested.params['field'], 'int') diff --git a/swh/model/tests/test_cli.py b/swh/model/tests/test_cli.py --- a/swh/model/tests/test_cli.py +++ b/swh/model/tests/test_cli.py @@ -8,14 +8,14 @@ import unittest from click.testing import CliRunner -from nose.plugins.attrib import attr +import pytest from swh.model import cli from swh.model.hashutil import hash_to_hex from swh.model.tests.test_from_disk import DataMixin -@attr('fs') +@pytest.mark.fr class TestIdentify(DataMixin, unittest.TestCase): def setUp(self): diff --git a/swh/model/tests/test_from_disk.py b/swh/model/tests/test_from_disk.py --- a/swh/model/tests/test_from_disk.py +++ b/swh/model/tests/test_from_disk.py @@ -8,7 +8,7 @@ import tempfile import unittest -from nose.plugins.attrib import attr +import pytest from swh.model import from_disk from swh.model.from_disk import Content, DentryPerms, Directory @@ -685,7 +685,7 @@ + 1) -@attr('fs') +@pytest.mark.fs class TarballTest(DataMixin, unittest.TestCase): def setUp(self): super().setUp() diff --git a/swh/model/tests/test_hashutil.py b/swh/model/tests/test_hashutil.py --- a/swh/model/tests/test_hashutil.py +++ b/swh/model/tests/test_hashutil.py @@ -107,7 +107,7 @@ hashes = MultiHash.from_path(f.name).digest() os.remove(f.name) - self.assertEquals(self.checksums, hashes) + self.assertEqual(self.checksums, hashes) class Hashutil(BaseHashutil): @@ -170,21 +170,21 @@ os.remove(f.name) self.checksums['length'] = len(self.data) - self.assertEquals(self.checksums, hashes) + self.assertEqual(self.checksums, hashes) def test_hash_to_hex(self): for type in self.checksums: hex = self.hex_checksums[type] hash = self.checksums[type] - self.assertEquals(hashutil.hash_to_hex(hex), hex) - self.assertEquals(hashutil.hash_to_hex(hash), hex) + self.assertEqual(hashutil.hash_to_hex(hex), hex) + self.assertEqual(hashutil.hash_to_hex(hash), hex) def test_hash_to_bytes(self): for type in self.checksums: hex = self.hex_checksums[type] hash = self.checksums[type] - self.assertEquals(hashutil.hash_to_bytes(hex), hash) - self.assertEquals(hashutil.hash_to_bytes(hash), hash) + self.assertEqual(hashutil.hash_to_bytes(hex), hash) + self.assertEqual(hashutil.hash_to_bytes(hash), hash) def test_hash_to_bytehex(self): for algo in self.checksums: @@ -201,10 +201,10 @@ try: hashutil._new_hash('blake2:10') except ValueError as e: - self.assertEquals(str(e), - 'Unexpected hashing algorithm blake2:10, ' - 'expected one of blake2b512, blake2s256, ' - 'sha1, sha1_git, sha256') + self.assertEqual(str(e), + 'Unexpected hashing algorithm blake2:10, ' + 'expected one of blake2b512, blake2s256, ' + 'sha1, sha1_git, sha256') @patch('hashlib.new') def test_new_hash_blake2b_blake2b512_builtin(self, mock_hashlib_new): diff --git a/swh/model/tests/test_identifiers.py b/swh/model/tests/test_identifiers.py --- a/swh/model/tests/test_identifiers.py +++ b/swh/model/tests/test_identifiers.py @@ -804,7 +804,7 @@ actual_value = identifiers.persistent_identifier( full_type, _hash, metadata=_meta) - self.assertEquals(actual_value, expected_persistent_id) + self.assertEqual(actual_value, expected_persistent_id) def test_persistent_identifier_wrong_input(self): _snapshot_id = 'notahash4bc0bf3d81436bf980b46e98bd338453' @@ -839,7 +839,7 @@ metadata={} ) actual_result = identifiers.parse_persistent_identifier(pid) - self.assertEquals(actual_result, expected_result) + self.assertEqual(actual_result, expected_result) for pid, _type, _version, _hash, _metadata in [ ('swh:1:cnt:9c95815d9e9d91b8dae8e05d8bbc696fe19f796b;lines=1-18;origin=https://github.com/python/cpython', # noqa @@ -862,7 +862,7 @@ metadata=_metadata ) actual_result = identifiers.parse_persistent_identifier(pid) - self.assertEquals(actual_result, expected_result) + self.assertEqual(actual_result, expected_result) def test_parse_persistent_identifier_parsing_error(self): for pid, _error in [ diff --git a/swh/model/tests/test_merkle.py b/swh/model/tests/test_merkle.py --- a/swh/model/tests/test_merkle.py +++ b/swh/model/tests/test_merkle.py @@ -8,7 +8,7 @@ from swh.model import merkle -class TestedMerkleNode(merkle.MerkleNode): +class MerkleTestNode(merkle.MerkleNode): type = 'tested_merkle_node_type' def __init__(self, data): @@ -29,7 +29,7 @@ ) -class TestedMerkleLeaf(merkle.MerkleLeaf): +class MerkleTestLeaf(merkle.MerkleLeaf): type = 'tested_merkle_leaf_type' def __init__(self, data): @@ -44,7 +44,7 @@ class TestMerkleLeaf(unittest.TestCase): def setUp(self): self.data = {'value': b'value'} - self.instance = TestedMerkleLeaf(self.data) + self.instance = MerkleTestLeaf(self.data) def test_hash(self): self.assertEqual(self.instance.compute_hash_called, 0) @@ -90,25 +90,25 @@ maxDiff = None def setUp(self): - self.root = TestedMerkleNode({'value': b'root'}) + self.root = MerkleTestNode({'value': b'root'}) self.nodes = {b'root': self.root} for i in (b'a', b'b', b'c'): value = b'root/' + i - node = TestedMerkleNode({ + node = MerkleTestNode({ 'value': value, }) self.root[i] = node self.nodes[value] = node for j in (b'a', b'b', b'c'): value2 = value + b'/' + j - node2 = TestedMerkleNode({ + node2 = MerkleTestNode({ 'value': value2, }) node[j] = node2 self.nodes[value2] = node2 for k in (b'a', b'b', b'c'): value3 = value2 + b'/' + j - node3 = TestedMerkleNode({ + node3 = MerkleTestNode({ 'value': value3, }) node2[j] = node3 @@ -188,8 +188,8 @@ hash_root = self.root.hash hash_b = self.root[b'b'].hash new_children = { - b'c': TestedMerkleNode({'value': b'root/b/new_c'}), - b'd': TestedMerkleNode({'value': b'root/b/d'}), + b'c': MerkleTestNode({'value': b'root/b/new_c'}), + b'd': MerkleTestNode({'value': b'root/b/d'}), } # collect all nodes @@ -219,7 +219,7 @@ # Ensure we collected root, root/b, and both new children collected_after_update = self.root.collect() self.assertCountEqual( - collected_after_update[TestedMerkleNode.type], + collected_after_update[MerkleTestNode.type], [self.nodes[b'root'].hash, self.nodes[b'root/b'].hash, new_children[b'c'].hash, new_children[b'd'].hash], ) diff --git a/swh/model/tests/test_validators.py b/swh/model/tests/test_validators.py --- a/swh/model/tests/test_validators.py +++ b/swh/model/tests/test_validators.py @@ -58,8 +58,8 @@ exc = cm.exception self.assertIsInstance(str(exc), str) - self.assertEquals(set(exc.error_dict.keys()), - {exceptions.NON_FIELD_ERRORS}) + self.assertEqual(set(exc.error_dict.keys()), + {exceptions.NON_FIELD_ERRORS}) hash_mismatches = exc.error_dict[exceptions.NON_FIELD_ERRORS] self.assertIsInstance(hash_mismatches, list) diff --git a/tox.ini b/tox.ini new file mode 100644 --- /dev/null +++ b/tox.ini @@ -0,0 +1,15 @@ +[tox] +envlist=flake8,py3 + +[testenv:py3] +deps = + pytest-cov +commands = + pytest --cov=swh --cov-branch {posargs} + +[testenv:flake8] +skip_install = true +deps = + flake8 +commands = + {envpython} -m flake8