Skip to content

Commit

Permalink
Create test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
jayvdb committed Dec 21, 2019
1 parent 510679d commit 1d91f1b
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ install:
- python setup.py sdist && version=$(python setup.py --version) && pushd dist && pip install stdlib-list-${version}.tar.gz && popd

script:
# FIXME: add some real test.
- python -c "import stdlib_list; print(stdlib_list.stdlib_list('$TRAVIS_PYTHON_VERSION'))"
- python tests/test_basic.py

deploy:
skip_cleanup: true
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ def read(*parts):
long_description="{}".format(read("README.md")),
long_description_content_type="text/markdown",
include_package_data=True,
packages=find_packages(),
packages=find_packages(exclude=["tests", "tests.*"]),
cmdclass=versioneer.get_cmdclass(),
)
80 changes: 80 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import unittest
import sys

import stdlib_list


class CurrentVersionBase(unittest.TestCase):

def setUp(self):
self.list = stdlib_list.stdlib_list(sys.version[:3])


class TestCurrentVersion(CurrentVersionBase):

def test_string(self):
self.assertIn('string', self.list)

def test_list_is_sorted(self):
self.assertEqual(sorted(self.list), self.list)

def test_builtin_modules(self):
"""Check all top level stdlib packages are recognised."""
unknown_builtins = set()
for module_name in sys.builtin_module_names:
if module_name not in self.list:
unknown_builtins.add(module_name)

self.assertFalse(sorted(unknown_builtins))


class TestSysModules(CurrentVersionBase):

# This relies on invocation in a clean python environment using unittest
# not using pytest.

ignore_list = [
'stdlib_list', 'functools32',
]

def setUp(self):
super(TestSysModules, self).setUp()
self.maxDiff = None

def test_preloaded_packages(self):
"""Check all top level stdlib packages are recognised."""
not_stdlib = set()
for module_name in sys.modules:
pkg, _, module = module_name.partition('.')
if pkg in self.ignore_list:
continue

# Avoid duplicating errors covered by other tests
if pkg in sys.builtin_module_names:
continue

if pkg not in self.list:
not_stdlib.add(pkg)

self.assertFalse(sorted(not_stdlib))

def test_preloaded_modules(self):
"""Check all stdlib modules are recognised."""
not_stdlib = set()
for module_name in sys.modules:
pkg, _, module = module_name.partition('.')
if pkg in self.ignore_list:
continue

# Avoid duplicating errors covered by other tests
if module_name in sys.builtin_module_names:
continue

if module_name not in self.list:
not_stdlib.add(module_name)

self.assertFalse(sorted(not_stdlib))


if __name__ == '__main__':
unittest.main()

0 comments on commit 1d91f1b

Please sign in to comment.