diff options
author | Taneli Hukkinen <hukkinj1@users.noreply.github.com> | 2021-02-09 23:10:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-09 15:10:30 -0600 |
commit | f0b4fd40fc4431329754b3be3cec0630827df98c (patch) | |
tree | 88048b69dff067a1d860ef599c0464e355f97089 | |
parent | 1282379d831ccc4306345fc7fcd09a0026694074 (diff) | |
download | immutables-f0b4fd40fc4431329754b3be3cec0630827df98c.tar.gz immutables-f0b4fd40fc4431329754b3be3cec0630827df98c.zip |
Fix flake8 errors and add it to CI (#45)
* Fix flake8 errors and add it to CI
* Use extras for test dependencies
Co-authored-by: Fantix King <fantix.king@gmail.com>
-rw-r--r-- | .github/workflows/tests.yml | 3 | ||||
-rw-r--r-- | immutables/map.py | 2 | ||||
-rw-r--r-- | setup.py | 14 | ||||
-rw-r--r-- | tests/test_issue24.py | 9 | ||||
-rw-r--r-- | tests/test_map.py | 14 | ||||
-rw-r--r-- | tests/test_none_keys.py | 8 |
6 files changed, 36 insertions, 14 deletions
diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dcc00be..971e850 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -49,5 +49,6 @@ jobs: - name: Test if: steps.release.outputs.version == 0 run: | - pip install -e . + pip install -e .[test] + flake8 immutables/ tests/ python -m unittest -v tests.suite diff --git a/immutables/map.py b/immutables/map.py index fe9dbaf..2c1ffa9 100644 --- a/immutables/map.py +++ b/immutables/map.py @@ -46,10 +46,12 @@ def map_bitindex(bitmap, bit): W_EMPTY, W_NEWNODE, W_NOT_FOUND = range(3) void = object() + class _Unhashable: __slots__ = () __hash__ = None + _NULL = _Unhashable() del _Unhashable @@ -3,6 +3,19 @@ import platform import setuptools +# Minimal dependencies required to test immutables. +TEST_DEPENDENCIES = [ + # pycodestyle is a dependency of flake8, but it must be frozen because + # their combination breaks too often + # (example breakage: https://gitlab.com/pycqa/flake8/issues/427) + 'flake8~=3.8.4', + 'pycodestyle~=2.6.0', +] + +EXTRA_DEPENDENCIES = { + 'test': TEST_DEPENDENCIES, +} + CFLAGS = ['-O2'] if platform.uname().system != 'Windows': CFLAGS.extend(['-std=c99', '-fsigned-char', '-Wall', @@ -73,4 +86,5 @@ setuptools.setup( provides=['immutables'], include_package_data=True, ext_modules=ext_modules, + extras_require=EXTRA_DEPENDENCIES, ) diff --git a/tests/test_issue24.py b/tests/test_issue24.py index afe6525..7d51e34 100644 --- a/tests/test_issue24.py +++ b/tests/test_issue24.py @@ -51,7 +51,7 @@ class Issue24Base: d = m.__dump__().splitlines() self.assertTrue(d) if d[0].startswith('HAMT'): - header = d[1] # skip _map.Map.__dump__() header + header = d[1] # skip _map.Map.__dump__() header else: header = d[0] self.dump_check_bitmap_node_count(header, 7) @@ -66,7 +66,7 @@ class Issue24Base: d = m2.__dump__().splitlines() self.assertTrue(d) if d[0].startswith('HAMT'): - header = d[1] # skip _map.Map.__dump__() header + header = d[1] # skip _map.Map.__dump__() header else: header = d[0] self.dump_check_bitmap_node_count(header, 4) @@ -79,7 +79,7 @@ class Issue24Base: self.assertTrue(len(d) > 3) # get node headers if d[0].startswith('HAMT'): - h1, h2 = d[1], d[3] # skip _map.Map.__dump__() header + h1, h2 = d[1], d[3] # skip _map.Map.__dump__() header else: h1, h2 = d[0], d[2] self.dump_check_node_kind(h1, 'Bitmap') @@ -96,12 +96,13 @@ class Issue24Base: self.assertTrue(len(d) > 3) # get node headers if d[0].startswith('HAMT'): - h1, h2 = d[1], d[3] # skip _map.Map.__dump__() header + h1, h2 = d[1], d[3] # skip _map.Map.__dump__() header else: h1, h2 = d[0], d[2] self.dump_check_node_kind(h1, 'Bitmap') self.dump_check_collision_node_count(h2, 4) + try: from immutables._map import Map as CMap except ImportError: diff --git a/tests/test_map.py b/tests/test_map.py index 4a473b3..9fffd8c 100644 --- a/tests/test_map.py +++ b/tests/test_map.py @@ -7,7 +7,12 @@ import unittest import weakref from immutables.map import Map as PyMap -from immutables._testutils import * # NoQA +from immutables._testutils import EqError +from immutables._testutils import HashKey +from immutables._testutils import HashKeyCrasher +from immutables._testutils import HashingError +from immutables._testutils import KeyStr +from immutables._testutils import ReprError class BaseMapTest: @@ -159,8 +164,6 @@ class BaseMapTest: # <Key name:E hash:362244>: 'e' # <Key name:B hash:101>: 'b' - - def test_map_stress_01(self): COLLECTION_SIZE = 7000 TEST_ITERS_EVERY = 647 @@ -1235,7 +1238,6 @@ class BaseMapTest: # node to be converted into an array node h = h.set(HashKey(i, i), i) - h = h.set(HashKey(18, '18-collision'), 18) with h.mutate() as m: @@ -1348,7 +1350,9 @@ class BaseMapTest: with self.assertRaisesRegex(TypeError, "can('t|not) pickle"): pickle.dumps(h.mutate()) - @unittest.skipIf(sys.version_info < (3, 7, 0), "__class_getitem__ is not available") + @unittest.skipIf( + sys.version_info < (3, 7, 0), "__class_getitem__ is not available" + ) def test_map_is_subscriptable(self): self.assertIs(self.Map[int, str], self.Map) diff --git a/tests/test_none_keys.py b/tests/test_none_keys.py index 92e7813..8c0bb37 100644 --- a/tests/test_none_keys.py +++ b/tests/test_none_keys.py @@ -1,7 +1,7 @@ import unittest from immutables.map import map_hash, map_mask, Map as PyMap -from immutables._testutils import * # NoQA +from immutables._testutils import HashKey none_hash = map_hash(None) @@ -342,7 +342,7 @@ class BaseNoneTest: self.assertTrue(key4 in m3) self.assertEqual(m3[key2], 2) self.assertEqual(m3[key4], 4) - self.assertFalse(None in m3) + self.assertFalse(None in m3) with self.assertRaises(KeyError): m3.delete(None) @@ -352,7 +352,7 @@ class BaseNoneTest: self.assertTrue(key4 in m3) self.assertEqual(m3[None], 9) self.assertEqual(m3[key4], 4) - self.assertFalse(key2 in m3) + self.assertFalse(key2 in m3) with self.assertRaises(KeyError): m3.delete(key2) @@ -362,7 +362,7 @@ class BaseNoneTest: self.assertTrue(key2 in m3) self.assertEqual(m3[None], 9) self.assertEqual(m3[key2], 2) - self.assertFalse(key4 in m3) + self.assertFalse(key4 in m3) with self.assertRaises(KeyError): m3.delete(key4) |