source: trunk/test_plugin/app/load/test_egg.py @ 1110

Revision 1110, 2.0 KB checked in by wehart, 5 years ago (diff)

An initial EGG loading test (that works!)

Line 
1#
2# Plugin load tests for eggs
3#
4
5import os
6import sys
7from os.path import abspath, dirname
8sys.path.insert(0, dirname(dirname(abspath(__file__)))+os.sep+".."+os.sep+"..")
9currdir = dirname(abspath(__file__))+os.sep
10
11import re
12import unittest
13from nose.tools import nottest
14import pyutilib_th
15import logging
16
17
18class TestEggLoader(pyutilib_th.TestCase):
19
20
21    def setUp(self):
22        p = re.compile("pyutilib")
23        global pyutilib
24        pyutilib = __import__("pyutilib")
25        pyutilib.plugin.PluginGlobals.push_env(pyutilib.plugin.PluginEnvironment())
26
27    def tearDown(self):
28        p = re.compile("pyutilib")
29        pyutilib.plugin.PluginGlobals.pop_env()
30        pyutilib.plugin.PluginGlobals.clear()
31        tmp = []
32        for item in sys.modules:
33            if p.match(str(item)):
34                tmp.append(str(item))
35        for item in tmp:
36            del sys.modules[item]
37        if "test1" in sys.modules:
38            del sys.modules["test1"]
39        if "test2" in sys.modules:
40            del sys.modules["test2"]
41        if "test3" in sys.modules:
42            del sys.modules["test3"]
43        for item in sys.modules:
44            if p.match(item):
45                print item
46
47    def test_egg1(self):
48        """Load an egg for the 'project1' project"""
49        service = pyutilib.plugin.PluginFactory("EggLoader",namespace="project1")
50        if service is None:
51            self.fail("Cannot test the PyUtilib EggLoader Plugin on this system because the pkg_resources package is not available.")
52        #
53        #
54        #
55        #logging.basicConfig(level=logging.DEBUG)
56        pyutilib.plugin.PluginGlobals.env().load_services(path=currdir+"eggs1")
57        pyutilib.setup_redirect(currdir+"egg1.out")
58        pyutilib.plugin.PluginGlobals.pprint(plugins=False)
59        #pyutilib.plugin.PluginGlobals.pprint()
60        pyutilib.reset_redirect()
61        self.failUnlessFileEqualsBaseline(currdir+"egg1.out", currdir+"egg1.txt")
62
63if __name__ == "__main__":
64   unittest.main()
Note: See TracBrowser for help on using the repository browser.