From a7c2b75d48587fce826613efced163272b11e354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Barrois?= Date: Tue, 20 Aug 2019 22:55:10 +0200 Subject: Lint test code. --- Makefile | 8 ++++++-- tests/django_test_app/__init__.py | 5 ++--- tests/django_test_app/models.py | 3 --- tests/setup_django.py | 1 - tests/test_base.py | 23 ++++++++++++++--------- tests/test_django.py | 6 ++---- tests/test_match.py | 1 - tests/test_parsing.py | 5 ++++- tests/test_spec.py | 26 +++++++++++++------------- 9 files changed, 41 insertions(+), 37 deletions(-) diff --git a/Makefile b/Makefile index 626f21c..ecf30e0 100644 --- a/Makefile +++ b/Makefile @@ -32,9 +32,13 @@ test: python -W default setup.py test # Note: we run the linter in two runs, because our __init__.py files has specific warnings we want to exclude -lint: +lint: check-manifest flake8 + +check-manifest: check-manifest - $(FLAKE8) --config .flake8 --exclude $(PACKAGE)/__init__.py $(PACKAGE) + +flake8: + $(FLAKE8) --config .flake8 --exclude $(PACKAGE)/__init__.py $(PACKAGE) $(TESTS_DIR) $(FLAKE8) --config .flake8 --ignore F401 $(PACKAGE)/__init__.py coverage: diff --git a/tests/django_test_app/__init__.py b/tests/django_test_app/__init__.py index 4506810..908f97e 100644 --- a/tests/django_test_app/__init__.py +++ b/tests/django_test_app/__init__.py @@ -3,9 +3,8 @@ # This code is distributed under the two-clause BSD License. try: # pragma: no cover - import django - from django.conf import settings + import django # noqa + from django.conf import settings # noqa django_loaded = True except ImportError: # pragma: no cover django_loaded = False - diff --git a/tests/django_test_app/models.py b/tests/django_test_app/models.py index 5313e89..3a43cfc 100644 --- a/tests/django_test_app/models.py +++ b/tests/django_test_app/models.py @@ -11,18 +11,15 @@ except ImportError: if django_loaded: from semantic_version import django_fields as semver_fields - class VersionModel(models.Model): version = semver_fields.VersionField(verbose_name='my version') spec = semver_fields.SpecField(verbose_name='my spec') - class PartialVersionModel(models.Model): partial = semver_fields.VersionField(partial=True, verbose_name='partial version') optional = semver_fields.VersionField(verbose_name='optional version', blank=True, null=True) optional_spec = semver_fields.SpecField(verbose_name='optional spec', blank=True, null=True) - class CoerceVersionModel(models.Model): version = semver_fields.VersionField(verbose_name='my version', coerce=True) partial = semver_fields.VersionField(verbose_name='partial version', coerce=True, partial=True) diff --git a/tests/setup_django.py b/tests/setup_django.py index 6a220df..1ea55e6 100644 --- a/tests/setup_django.py +++ b/tests/setup_django.py @@ -27,4 +27,3 @@ if django_loaded: django.setup() from django.apps import apps apps.populate(settings.INSTALLED_APPS) - diff --git a/tests/test_base.py b/tests/test_base.py index 6470e90..76d120b 100755 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -9,6 +9,7 @@ import unittest from semantic_version import base + class ComparisonTestCase(unittest.TestCase): def test_identifier_cmp(self): cases = [ @@ -232,14 +233,17 @@ class VersionTestCase(unittest.TestCase): self.assertNotEqual(text, base.Version(text, partial=True)) def test_hash(self): - self.assertEqual(1, + self.assertEqual( + 1, len(set([base.Version('0.1.0'), base.Version('0.1.0')]))) - self.assertEqual(2, + self.assertEqual( + 2, len(set([base.Version('0.1.0'), base.Version('0.1.0', partial=True)]))) # A fully-defined 'partial' version isn't actually partial. - self.assertEqual(1, + self.assertEqual( + 1, len(set([ base.Version('0.1.0-a1+34'), base.Version('0.1.0-a1+34', partial=True) @@ -432,7 +436,6 @@ class SpecItemTestCase(unittest.TestCase): '==0.1.2+build3.14': (base.SpecItem.KIND_EQUAL, 0, 1, 2, (), ('build3', '14')), '<=0.1.1': (base.SpecItem.KIND_LTE, 0, 1, 1, None, None), '<0.1.1': (base.SpecItem.KIND_LT, 0, 1, 1, None, None), - '<=0.1.1': (base.SpecItem.KIND_LTE, 0, 1, 1, None, None), '!=0.1.1+': (base.SpecItem.KIND_NEQ, 0, 1, 1, (), ()), '<=0.1.1-': (base.SpecItem.KIND_LTE, 0, 1, 1, (), None), '>=0.2.3-rc2': (base.SpecItem.KIND_GTE, 0, 2, 3, ('rc2',), None), @@ -487,9 +490,9 @@ class SpecItemTestCase(unittest.TestCase): ['0.1.0', '0.0.0'], ['0.1.1', '0.1.1-zzz+999', '1.2.0', '0.1.1+build3'], ), - '<=0.1.1': ( - ['0.1.1+build4', '0.1.1-alpha', '0.1.0'], - ['0.2.3', '1.1.1', '0.1.2'], + '<=0.1.2': ( + ['0.1.2+build4', '0.1.2-alpha', '0.1.0'], + ['0.2.3', '1.1.1', '0.1.3'], ), '<0.1.1-': ( ['0.1.0', '0.1.1-alpha', '0.1.1-alpha+4'], @@ -578,7 +581,8 @@ class SpecItemTestCase(unittest.TestCase): self.assertEqual(base.SpecItem.KIND_EQUAL, spec.kind) def test_hash(self): - self.assertEqual(1, + self.assertEqual( + 1, len(set([base.SpecItem('==0.1.0'), base.SpecItem('==0.1.0')]))) @@ -755,7 +759,8 @@ class SpecTestCase(unittest.TestCase): self.assertFalse('ii' in base.Spec('>=0.1.1')) def test_hash(self): - self.assertEqual(1, + self.assertEqual( + 1, len(set([base.Spec('>=0.1.1'), base.Spec('>=0.1.1')]))) diff --git a/tests/test_django.py b/tests/test_django.py index b61b64e..6f4d872 100644 --- a/tests/test_django.py +++ b/tests/test_django.py @@ -3,7 +3,6 @@ # This code is distributed under the two-clause BSD License. import unittest -import sys import semantic_version @@ -14,8 +13,6 @@ if django_loaded: # pragma: no cover from semantic_version import django_fields from .django_test_app import models - import django - from django.conf import settings from django.core import serializers from django.core.management import call_command from django.db import connection @@ -168,7 +165,8 @@ class DjangoFieldTestCase(unittest.TestCase): def test_serialization(self): o1 = models.VersionModel(version=Version('0.1.1'), spec=Spec('==0.1.1,!=0.1.1-alpha')) - o2 = models.VersionModel(version=Version('0.4.3-rc3+build3'), + o2 = models.VersionModel( + version=Version('0.4.3-rc3+build3'), spec=Spec('<=0.1.1-rc2,!=0.1.1-rc1')) data = serializers.serialize('json', [o1, o2]) diff --git a/tests/test_match.py b/tests/test_match.py index 10a9c8a..16d7e5a 100755 --- a/tests/test_match.py +++ b/tests/test_match.py @@ -175,4 +175,3 @@ class MatchTestCase(unittest.TestCase): if __name__ == '__main__': # pragma: no cover unittest.main() - diff --git a/tests/test_parsing.py b/tests/test_parsing.py index 548826a..2d612a1 100755 --- a/tests/test_parsing.py +++ b/tests/test_parsing.py @@ -34,7 +34,10 @@ class ParsingTestCase(unittest.TestCase): ('0.1.2-rc1', [0, 1, 2, ('rc1',), ()]), ('0.1.2-rc1.3.4', [0, 1, 2, ('rc1', '3', '4'), ()]), ('0.1.2+build42-12.2012-01-01.12h23', [0, 1, 2, (), ('build42-12', '2012-01-01', '12h23')]), - ('0.1.2-rc1.3-14.15+build.2012-01-01.11h34', [0, 1, 2, ('rc1', '3-14', '15'), ('build', '2012-01-01', '11h34')]), + ( + '0.1.2-rc1.3-14.15+build.2012-01-01.11h34', + [0, 1, 2, ('rc1', '3-14', '15'), ('build', '2012-01-01', '11h34')], + ), ] def test_invalid(self): diff --git a/tests/test_spec.py b/tests/test_spec.py index cd5d2ce..b5fcd98 100644 --- a/tests/test_spec.py +++ b/tests/test_spec.py @@ -17,7 +17,7 @@ class FormatTests(unittest.TestCase): """Tests proper version validation.""" def test_major_minor_patch(self): - ### SPEC: + # SPEC: # A normal version number MUST take the form X.Y.Z with self.assertRaises(ValueError): @@ -29,7 +29,7 @@ class FormatTests(unittest.TestCase): with self.assertRaises(ValueError): Version('1.2.3.4') - ### SPEC: + # SPEC: # Where X, Y, and Z are non-negative integers, with self.assertRaises(ValueError): @@ -42,8 +42,7 @@ class FormatTests(unittest.TestCase): self.assertEqual(2, v.minor) self.assertEqual(3, v.patch) - - ### Spec: + # SPEC: # And MUST NOT contain leading zeroes with self.assertRaises(ValueError): Version('1.2.01') @@ -58,7 +57,7 @@ class FormatTests(unittest.TestCase): self.assertEqual(0, v.patch) def test_prerelease(self): - ### SPEC: + # SPEC: # A pre-release version MAY be denoted by appending a hyphen and a # series of dot separated identifiers immediately following the patch # version. @@ -69,7 +68,7 @@ class FormatTests(unittest.TestCase): v = Version('1.2.3-23') self.assertEqual(('23',), v.prerelease) - ### SPEC: + # SPEC: # Identifiers MUST comprise only ASCII alphanumerics and hyphen. # Identifiers MUST NOT be empty with self.assertRaises(ValueError): @@ -77,7 +76,7 @@ class FormatTests(unittest.TestCase): with self.assertRaises(ValueError): Version('1.2.3-..') - ### SPEC: + # SPEC: # Numeric identifiers MUST NOT include leading zeroes. with self.assertRaises(ValueError): @@ -89,7 +88,7 @@ class FormatTests(unittest.TestCase): self.assertEqual(('0a', '0', '000zz'), v.prerelease) def test_build(self): - ### SPEC: + # SPEC: # Build metadata MAY be denoted by appending a plus sign and a series of # dot separated identifiers immediately following the patch or # pre-release version @@ -99,7 +98,7 @@ class FormatTests(unittest.TestCase): with self.assertRaises(ValueError): Version('1.2.3 +4') - ### SPEC: + # SPEC: # Identifiers MUST comprise only ASCII alphanumerics and hyphen. # Identifiers MUST NOT be empty with self.assertRaises(ValueError): @@ -112,7 +111,7 @@ class FormatTests(unittest.TestCase): self.assertEqual(('0', '0a', '01'), v.build) def test_precedence(self): - ### SPEC: + # SPEC: # Precedence is determined by the first difference when comparing from # left to right as follows: Major, minor, and patch versions are always # compared numerically. @@ -121,13 +120,13 @@ class FormatTests(unittest.TestCase): self.assertLess(Version('2.0.0'), Version('2.1.0')) self.assertLess(Version('2.1.0'), Version('2.1.1')) - ### SPEC: + # SPEC: # When major, minor, and patch are equal, a pre-release version has # lower precedence than a normal version. # Example: 1.0.0-alpha < 1.0.0 self.assertLess(Version('1.0.0-alpha'), Version('1.0.0')) - ### SPEC: + # SPEC: # Precedence for two pre-release versions with the same major, minor, # and patch version MUST be determined by comparing each dot separated # identifier from left to right until a difference is found as follows: @@ -146,7 +145,8 @@ class FormatTests(unittest.TestCase): # smaller set, if all of the preceding identifiers are equal. self.assertLess(Version('1.0.0-a.b.c'), Version('1.0.0-a.b.c.0')) - # Example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0. + # Example: 1.0.0-alpha < 1.0.0-alpha.1 < 1.0.0-alpha.beta + # < 1.0.0-beta < 1.0.0-beta.2 < 1.0.0-beta.11 < 1.0.0-rc.1 < 1.0.0. self.assertLess(Version('1.0.0-alpha'), Version('1.0.0-alpha.1')) self.assertLess(Version('1.0.0-alpha.1'), Version('1.0.0-alpha.beta')) self.assertLess(Version('1.0.0-alpha.beta'), Version('1.0.0-beta')) -- cgit v1.2.1