Skip to content

Commit

Permalink
Don't ship eggs for testing (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdickinson committed Feb 3, 2022
1 parent eb6c175 commit 6e5c7ba
Show file tree
Hide file tree
Showing 29 changed files with 119 additions and 24 deletions.
2 changes: 2 additions & 0 deletions envisage/tests/bad_eggs/README.txt
@@ -0,0 +1,2 @@
This directory contains packages used by the test suite to create eggs
for testing purposes.
Binary file removed envisage/tests/bad_eggs/acme.bad-0.1a1-py3.10.egg
Binary file not shown.
Binary file removed envisage/tests/bad_eggs/acme.bad-0.1a1-py3.5.egg
Binary file not shown.
Binary file removed envisage/tests/bad_eggs/acme.bad-0.1a1-py3.6.egg
Binary file not shown.
Binary file removed envisage/tests/bad_eggs/acme.bad-0.1a1-py3.7.egg
Binary file not shown.
Binary file removed envisage/tests/bad_eggs/acme.bad-0.1a1-py3.8.egg
Binary file not shown.
Binary file removed envisage/tests/bad_eggs/acme.bad-0.1a1-py3.9.egg
Binary file not shown.
14 changes: 2 additions & 12 deletions envisage/tests/eggs/README.txt
@@ -1,12 +1,2 @@
This directory contains eggs used by the test suite, along with the packages
that were used to generate those eggs.

To generate eggs for a new version of Python:

- Change to the acme.bar directory
- Run "python setup.py bdist_egg" using the desired version of Python. This
will create a new egg under the "dist/" directory.
- Copy that egg to this directory.

Now repeat for acme.baz and acme.foo, as well as acme.bad in the bad_eggs
directory adjacent to this one.
This directory contains packages used by the test suite to create eggs
for testing purposes.
Binary file removed envisage/tests/eggs/acme.bar-0.1a1-py3.10.egg
Binary file not shown.
Binary file removed envisage/tests/eggs/acme.bar-0.1a1-py3.5.egg
Binary file not shown.
Binary file removed envisage/tests/eggs/acme.bar-0.1a1-py3.6.egg
Binary file not shown.
Binary file removed envisage/tests/eggs/acme.bar-0.1a1-py3.7.egg
Binary file not shown.
Binary file removed envisage/tests/eggs/acme.bar-0.1a1-py3.8.egg
Binary file not shown.
Binary file removed envisage/tests/eggs/acme.bar-0.1a1-py3.9.egg
Binary file not shown.
Binary file removed envisage/tests/eggs/acme.baz-0.1a1-py3.10.egg
Binary file not shown.
Binary file removed envisage/tests/eggs/acme.baz-0.1a1-py3.5.egg
Binary file not shown.
Binary file removed envisage/tests/eggs/acme.baz-0.1a1-py3.6.egg
Binary file not shown.
Binary file removed envisage/tests/eggs/acme.baz-0.1a1-py3.7.egg
Binary file not shown.
Binary file removed envisage/tests/eggs/acme.baz-0.1a1-py3.8.egg
Binary file not shown.
Binary file removed envisage/tests/eggs/acme.baz-0.1a1-py3.9.egg
Binary file not shown.
Binary file removed envisage/tests/eggs/acme.foo-0.1a1-py3.10.egg
Binary file not shown.
Binary file removed envisage/tests/eggs/acme.foo-0.1a1-py3.5.egg
Binary file not shown.
Binary file removed envisage/tests/eggs/acme.foo-0.1a1-py3.6.egg
Binary file not shown.
Binary file removed envisage/tests/eggs/acme.foo-0.1a1-py3.7.egg
Binary file not shown.
Binary file removed envisage/tests/eggs/acme.foo-0.1a1-py3.8.egg
Binary file not shown.
Binary file removed envisage/tests/eggs/acme.foo-0.1a1-py3.9.egg
Binary file not shown.
70 changes: 66 additions & 4 deletions envisage/tests/test_egg_based.py
Expand Up @@ -10,20 +10,82 @@
""" Base class for Egg-based test cases. """


from os.path import dirname, join
from os.path import join
import shutil
import subprocess
import sys
import tempfile
import unittest

import pkg_resources


def build_egg(egg_dir, dist_dir):
"""Helper function to build an egg.
Parameters
----------
egg_dir : str
Directory containing the Python package to be built. Should
contain a "setup.py" file that can be used with
"python setup.py bdist_egg" to build the package.
dist_dir : str
Directory to place the built egg in. The directory should
already exist.
"""
subprocess.run(
[
"python",
"setup.py",
"bdist_egg",
"--dist-dir",
dist_dir,
],
cwd=egg_dir,
check=True,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)


class EggBasedTestCase(unittest.TestCase):
""" Base class for Egg-based test cases. """

@classmethod
def setUpClass(cls):
"""
Create eggs for testing purposes.
"""
cls.egg_dir = tempfile.mkdtemp()
eggs_root_dir = pkg_resources.resource_filename(
"envisage.tests", "eggs")
for egg_name in ["acme.bar", "acme.baz", "acme.foo"]:
build_egg(
egg_dir=join(eggs_root_dir, egg_name),
dist_dir=cls.egg_dir,
)

@classmethod
def tearDownClass(cls):
"""
Delete created eggs.
"""
shutil.rmtree(cls.egg_dir)

def setUp(self):
""" Prepares the test fixture before each test method is called. """

# The location of the 'eggs' directory.
self.egg_dir = join(dirname(__file__), "eggs")
# Some tests cause sys.path to be modified. Capture the original
# contents so that we can restore sys.path later.
self._original_sys_path_contents = sys.path[:]

def tearDown(self):
""" Called immediately after each test method has been called. """

# Undo any sys.path modifications
sys.path[:] = self._original_sys_path_contents

pkg_resources.working_set = pkg_resources.WorkingSet()

def _add_egg(self, filename, working_set=None):
""" Create and add a distribution from the specified '.egg'. """
Expand All @@ -32,7 +94,7 @@ def _add_egg(self, filename, working_set=None):
working_set = pkg_resources.working_set

# The eggs must be in our egg directory!
filename = join(dirname(__file__), "eggs", filename)
filename = join(self.egg_dir, filename)

# Create a distribution for the egg.
distributions = pkg_resources.find_distributions(filename)
Expand Down
41 changes: 35 additions & 6 deletions envisage/tests/test_egg_basket_plugin_manager.py
Expand Up @@ -10,33 +10,62 @@
""" Tests for the 'Egg Basket' plugin manager. """

import glob
from os.path import basename, dirname, join
from os.path import basename, join
import shutil
import tempfile
import sys
import tempfile
import unittest

import pkg_resources

from envisage.egg_basket_plugin_manager import EggBasketPluginManager
from envisage.tests.test_egg_based import build_egg


class EggBasketPluginManagerTestCase(unittest.TestCase):
""" Tests for the 'Egg Basket' plugin manager. """

#### 'unittest.TestCase' protocol #########################################

@classmethod
def setUpClass(cls):
"""
Create eggs for testing purposes.
"""
cls.eggs_dir = tempfile.mkdtemp()
cls.bad_eggs_dir = tempfile.mkdtemp()

eggs_root_dir = pkg_resources.resource_filename(
"envisage.tests", "eggs")
for egg_name in ["acme.bar", "acme.baz", "acme.foo"]:
build_egg(
egg_dir=join(eggs_root_dir, egg_name),
dist_dir=cls.eggs_dir,
)

bad_eggs_root_dir = pkg_resources.resource_filename(
"envisage.tests", "bad_eggs")
for egg_name in ["acme.bad"]:
build_egg(
egg_dir=join(bad_eggs_root_dir, egg_name),
dist_dir=cls.bad_eggs_dir,
)

@classmethod
def tearDownClass(cls):
"""
Delete created eggs.
"""
shutil.rmtree(cls.bad_eggs_dir)
shutil.rmtree(cls.eggs_dir)

def setUp(self):
""" Prepares the test fixture before each test method is called. """

# Some tests cause sys.path to be modified. Capture the original
# contents so that we can restore sys.path later.
self._original_sys_path_contents = sys.path[:]

# The location of the 'eggs' test data directory.
self.eggs_dir = join(dirname(__file__), "eggs")
self.bad_eggs_dir = join(dirname(__file__), "bad_eggs")

def tearDown(self):
""" Called immediately after each test method has been called. """

Expand Down
16 changes: 14 additions & 2 deletions setup.py
Expand Up @@ -330,8 +330,20 @@ def get_long_description():
"demo/*/*/*/*/*/*",
],
"envisage.tests": [
"bad_eggs/*.egg",
"eggs/*.egg",
"bad_eggs/README.txt",
"bad_eggs/acme.bad/setup.py",
"bad_eggs/acme.bad/acme/*.py",
"bad_eggs/acme.bad/acme/bad/*.py",
"eggs/README.txt",
"eggs/acme.bar/setup.py",
"eggs/acme.bar/acme/*.py",
"eggs/acme.bar/acme/bar/*.py",
"eggs/acme.baz/setup.py",
"eggs/acme.baz/acme/*.py",
"eggs/acme.baz/acme/baz/*.py",
"eggs/acme.foo/setup.py",
"eggs/acme.foo/acme/*.py",
"eggs/acme.foo/acme/foo/*.py",
"plugins/pear/*.py",
"plugins/banana/*.py",
"plugins/orange/*.py",
Expand Down

0 comments on commit 6e5c7ba

Please sign in to comment.