Skip to content

Commit

Permalink
Make some more code style changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
vsajip committed Mar 19, 2024
1 parent aed6a13 commit 674a491
Show file tree
Hide file tree
Showing 8 changed files with 121 additions and 178 deletions.
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ per-file-ignores =
docs/conf.py:E302,E265,E401,E402
tests/support.py:F401
tests/test_all.py:E402
tests/test_util.py:E401
tests/distlib_tests.py:F401,E402

12 changes: 4 additions & 8 deletions tests/distlib_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@

_ver = sys.version_info[:2]

from test_database import (DataFilesTestCase, TestDatabase, TestDistribution,
TestEggInfoDistribution, DepGraphTestCase)
from test_database import (DataFilesTestCase, TestDatabase, TestDistribution, TestEggInfoDistribution, DepGraphTestCase)
from test_index import PackageIndexTestCase
from test_locators import LocatorTestCase
from test_manifest import ManifestTestCase
from test_markers import MarkersTestCase
from test_metadata import MetadataTestCase, LegacyMetadataTestCase
from test_resources import (ZipResourceTestCase, FileResourceTestCase,
CacheTestCase)
from test_resources import (ZipResourceTestCase, FileResourceTestCase, CacheTestCase)
from test_scripts import ScriptTestCase
from test_version import (VersionTestCase, CompatibilityTestCase,
LegacyVersionTestCase, SemanticVersionTestCase)
from test_version import (VersionTestCase, CompatibilityTestCase, LegacyVersionTestCase, SemanticVersionTestCase)
from test_wheel import WheelTestCase

from test_util import (UtilTestCase, ProgressTestCase, FileOpsTestCase,
GlobTestCase)
from test_util import (UtilTestCase, ProgressTestCase, FileOpsTestCase, GlobTestCase)
14 changes: 7 additions & 7 deletions tests/test_locators.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,10 +372,10 @@ def test_prereleases(self):
self.assertEqual(actual[0].name_and_version, 'SQLAlchemy (0.6beta3)')
dists, problems = finder.find(dist)
# Test changed since now prereleases as found as a last resort.
#self.assertEqual(dists, set([dist]))
#self.assertEqual(len(problems), 1)
#problem = problems.pop()
#self.assertEqual(problem, ('unsatisfied', REQT))
# self.assertEqual(dists, set([dist]))
# self.assertEqual(len(problems), 1)
# problem = problems.pop()
# self.assertEqual(problem, ('unsatisfied', REQT))
self.assertEqual(dists, set([actual[0], dist]))
self.assertFalse(problems)

Expand Down Expand Up @@ -411,9 +411,9 @@ def test_all_versions(self):
'setuptools-0.6b4.zip',
'setuptools-0.6c10.tar.gz',
'setuptools-0.6c11.tar.gz',
#'setuptools-0.6c12dev-r88997.tar.gz',
#'setuptools-0.6c12dev-r88998.tar.gz',
#'setuptools-0.6c12dev-r89000.tar.gz',
# 'setuptools-0.6c12dev-r88997.tar.gz',
# 'setuptools-0.6c12dev-r88998.tar.gz',
# 'setuptools-0.6c12dev-r89000.tar.gz',
'setuptools-0.6c1.zip',
'setuptools-0.6c2.zip',
'setuptools-0.6c3.tar.gz',
Expand Down
23 changes: 9 additions & 14 deletions tests/test_markers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from distlib.markers import interpret
from distlib.util import in_venv


class MarkersTestCase(DistlibTestCase):

def test_interpret(self):
Expand All @@ -26,22 +27,17 @@ def test_interpret(self):
platform_python_implementation = python_implementation()

self.assertTrue(interpret("sys_platform == '%s'" % sys_platform))
self.assertTrue(interpret(
"sys_platform == '%s' and python_full_version == '%s'" %
(sys_platform, version)))
self.assertTrue(interpret("sys_platform == '%s' and python_full_version == '%s'" % (sys_platform, version)))
self.assertTrue(interpret("'%s' == sys_platform" % sys_platform))
self.assertTrue(interpret('os_name == "%s"' % os_name))
self.assertTrue(interpret(
'platform_version == "%s" and platform_machine == "%s"' %
(platform_version, platform_machine)))
self.assertTrue(interpret('platform_python_implementation == "%s"' %
platform_python_implementation))
self.assertTrue(
interpret('platform_version == "%s" and platform_machine == "%s"' % (platform_version, platform_machine)))
self.assertTrue(interpret('platform_python_implementation == "%s"' % platform_python_implementation))

self.assertTrue(interpret('platform_in_venv == "%s"' % in_venv()))

# stuff that need to raise a syntax error
ops = ('os_name == 2', "'2' == '2'",
'okpjonon', '', 'os_name ==', 'python_version == 2.4')
ops = ('os_name == 2', "'2' == '2'", 'okpjonon', '', 'os_name ==', 'python_version == 2.4')
for op in ops:
self.assertRaises(SyntaxError, interpret, op)

Expand Down Expand Up @@ -75,8 +71,7 @@ def test_interpret(self):
self.assertTrue(interpret("'%s' in os_name" % os_name))
self.assertTrue(interpret("'buuuu' not in os_name"))
self.assertTrue(interpret("'buu' in os_name", {'os_name': 'buuu'}))
self.assertTrue(interpret(
"'buuuu' not in os_name and '%s' in os_name" % os_name))
self.assertTrue(interpret("'buuuu' not in os_name and '%s' in os_name" % os_name))

# normalized version comparison correctness
self.assertTrue(interpret('python_version > "5.0"', {'python_version': '10.0'}))
Expand All @@ -85,8 +80,7 @@ def test_interpret(self):
self.assertTrue(interpret('python_full_version > "5.0"', {'python_full_version': '10.0'}))

# execution context
self.assertTrue(interpret('python_version == "0.1"',
{'python_version': '0.1'}))
self.assertTrue(interpret('python_version == "0.1"', {'python_version': '0.1'}))

# parentheses and extra
if sys.platform != 'win32':
Expand All @@ -97,5 +91,6 @@ def test_interpret(self):
"and extra == 'quux'" % relop)
self.assertTrue(interpret(expression, {'extra': 'quux'}))


if __name__ == '__main__': # pragma: no cover
unittest.main()
61 changes: 23 additions & 38 deletions tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
HERE = os.path.abspath(os.path.dirname(__file__))
IN_GITHUB_WORKFLOW = in_github_workflow()


class ZipResourceTestCase(DistlibTestCase):

def setUp(self):
sys.path.insert(0, os.path.join(HERE, 'foo.zip'))

Expand Down Expand Up @@ -114,31 +116,21 @@ def test_iterator(self):
f = finder('foo')
iterator = f.iterator('')
actual = set([(r.name, r.is_container) for r in iterator])
expected = set([
('', True),
('foo_resource.bin', False),
('bar/bar_resource.bin', False),
('bar/baz.py', False),
('__init__.py', False),
('bar', True),
('bar/__init__.py', False)
])
expected = set([('', True), ('foo_resource.bin', False), ('bar/bar_resource.bin', False), ('bar/baz.py', False),
('__init__.py', False), ('bar', True), ('bar/__init__.py', False)])
self.assertEqual(actual, expected)
iterator = f.iterator('bar')
actual = set([(r.name, r.is_container) for r in iterator])
expected = set([
('bar/baz.py', False),
('bar', True),
('bar/bar_resource.bin', False),
('bar/__init__.py', False)
])
expected = set([('bar/baz.py', False), ('bar', True), ('bar/bar_resource.bin', False),
('bar/__init__.py', False)])
self.assertEqual(actual, expected)
iterator = f.iterator('bar/bar_resource.bin')
actual = set([(r.name, r.is_container) for r in iterator])
self.assertEqual(actual, set([('bar/bar_resource.bin', False)]))


class FileResourceTestCase(DistlibTestCase):

def setUp(self):
sys.path.insert(0, HERE)

Expand Down Expand Up @@ -220,32 +212,30 @@ def test_iterator(self):
f = finder('foofoo')
iterator = f.iterator('')
actual = set([(r.name, r.is_container) for r in iterator])
expected = set([('', True),
('nested/nested_resource.bin', False),
('bar', True),
('__init__.py', False),
('nested', True),
('bar/bar_resource.bin', False),
('bar/__init__.py', False),
('bar/baz.py', False),
('foo_resource.bin', False),
])
expected = set([
('', True),
('nested/nested_resource.bin', False),
('bar', True),
('__init__.py', False),
('nested', True),
('bar/bar_resource.bin', False),
('bar/__init__.py', False),
('bar/baz.py', False),
('foo_resource.bin', False),
])
self.assertEqual(actual, expected)
iterator = f.iterator('bar')
actual = set([(r.name, r.is_container) for r in iterator])
expected = set([
('bar/baz.py', False),
('bar', True),
('bar/bar_resource.bin', False),
('bar/__init__.py', False)
])
expected = set([('bar/baz.py', False), ('bar', True), ('bar/bar_resource.bin', False),
('bar/__init__.py', False)])
self.assertEqual(actual, expected)
iterator = f.iterator('bar/bar_resource.bin')
actual = set([(r.name, r.is_container) for r in iterator])
self.assertEqual(actual, set([('bar/bar_resource.bin', False)]))


class CacheTestCase(DistlibTestCase):

def test_base(self):
cache = ResourceCache()
expected = os.path.join(get_cache_base(), str('resource-cache'))
Expand All @@ -262,13 +252,8 @@ def test_filepath(self):
sys.path.insert(0, path)
self.addCleanup(sys.path.remove, path)

cases = (
('foo', 'foo_resource.bin'),
('foo', 'bar/bar_resource.bin'),
('foofoo', 'bar/bar_resource.bin'),
('barbar', 'bar_resource.bin'),
('barbar.baz', 'baz_resource.bin')
)
cases = (('foo', 'foo_resource.bin'), ('foo', 'bar/bar_resource.bin'), ('foofoo', 'bar/bar_resource.bin'),
('barbar', 'bar_resource.bin'), ('barbar.baz', 'baz_resource.bin'))

for pkg, path in cases:
f = finder(pkg)
Expand Down
Loading

0 comments on commit 674a491

Please sign in to comment.