Commit 8fdf7763 authored by Jason R. Coombs's avatar Jason R. Coombs

Update test_find_packages to use pytest

parent 08bac0ab
...@@ -3,7 +3,6 @@ import os ...@@ -3,7 +3,6 @@ import os
import sys import sys
import shutil import shutil
import tempfile import tempfile
import unittest
import platform import platform
import pytest import pytest
...@@ -34,13 +33,13 @@ def has_symlink(): ...@@ -34,13 +33,13 @@ def has_symlink():
) )
return can_symlink() and not bad_symlink return can_symlink() and not bad_symlink
class TestFindPackages(unittest.TestCase): class TestFindPackages:
def setUp(self): def setup_method(self, method):
self.dist_dir = tempfile.mkdtemp() self.dist_dir = tempfile.mkdtemp()
self._make_pkg_structure() self._make_pkg_structure()
def tearDown(self): def teardown_method(self, method):
shutil.rmtree(self.dist_dir) shutil.rmtree(self.dist_dir)
def _make_pkg_structure(self): def _make_pkg_structure(self):
...@@ -88,7 +87,7 @@ class TestFindPackages(unittest.TestCase): ...@@ -88,7 +87,7 @@ class TestFindPackages(unittest.TestCase):
def test_regular_package(self): def test_regular_package(self):
self._touch('__init__.py', self.pkg_dir) self._touch('__init__.py', self.pkg_dir)
packages = find_packages(self.dist_dir) packages = find_packages(self.dist_dir)
self.assertEqual(packages, ['pkg', 'pkg.subpkg']) assert packages == ['pkg', 'pkg.subpkg']
def test_exclude(self): def test_exclude(self):
self._touch('__init__.py', self.pkg_dir) self._touch('__init__.py', self.pkg_dir)
...@@ -103,7 +102,7 @@ class TestFindPackages(unittest.TestCase): ...@@ -103,7 +102,7 @@ class TestFindPackages(unittest.TestCase):
alt_dir = self._mkdir('other_pkg', self.dist_dir) alt_dir = self._mkdir('other_pkg', self.dist_dir)
self._touch('__init__.py', alt_dir) self._touch('__init__.py', alt_dir)
packages = find_packages(self.dist_dir, include=['other_pkg']) packages = find_packages(self.dist_dir, include=['other_pkg'])
self.assertEqual(packages, ['other_pkg']) assert packages == ['other_pkg']
def test_dir_with_dot_is_skipped(self): def test_dir_with_dot_is_skipped(self):
shutil.rmtree(os.path.join(self.dist_dir, 'pkg/subpkg/assets')) shutil.rmtree(os.path.join(self.dist_dir, 'pkg/subpkg/assets'))
...@@ -111,7 +110,7 @@ class TestFindPackages(unittest.TestCase): ...@@ -111,7 +110,7 @@ class TestFindPackages(unittest.TestCase):
self._touch('__init__.py', data_dir) self._touch('__init__.py', data_dir)
self._touch('file.dat', data_dir) self._touch('file.dat', data_dir)
packages = find_packages(self.dist_dir) packages = find_packages(self.dist_dir)
self.assertTrue('pkg.some.data' not in packages) assert 'pkg.some.data' not in packages
def test_dir_with_packages_in_subdir_is_excluded(self): def test_dir_with_packages_in_subdir_is_excluded(self):
""" """
...@@ -122,7 +121,7 @@ class TestFindPackages(unittest.TestCase): ...@@ -122,7 +121,7 @@ class TestFindPackages(unittest.TestCase):
build_pkg_dir = self._mkdir('pkg', build_dir) build_pkg_dir = self._mkdir('pkg', build_dir)
self._touch('__init__.py', build_pkg_dir) self._touch('__init__.py', build_pkg_dir)
packages = find_packages(self.dist_dir) packages = find_packages(self.dist_dir)
self.assertTrue('build.pkg' not in packages) assert 'build.pkg' not in packages
@pytest.mark.skipif(not has_symlink(), reason='Symlink support required') @pytest.mark.skipif(not has_symlink(), reason='Symlink support required')
def test_symlinked_packages_are_included(self): def test_symlinked_packages_are_included(self):
...@@ -137,10 +136,10 @@ class TestFindPackages(unittest.TestCase): ...@@ -137,10 +136,10 @@ class TestFindPackages(unittest.TestCase):
os.symlink('pkg', linked_pkg) os.symlink('pkg', linked_pkg)
assert os.path.isdir(linked_pkg) assert os.path.isdir(linked_pkg)
packages = find_packages(self.dist_dir) packages = find_packages(self.dist_dir)
self.assertTrue('lpkg' in packages) assert 'lpkg' in packages
def _assert_packages(self, actual, expected): def _assert_packages(self, actual, expected):
self.assertEqual(set(actual), set(expected)) assert set(actual) == set(expected)
def test_pep420_ns_package(self): def test_pep420_ns_package(self):
packages = find_420_packages( packages = find_420_packages(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment