File: test_zipimport_jy.py

package info (click to toggle)
jython 2.5.3-16%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 43,772 kB
  • ctags: 106,434
  • sloc: python: 351,322; java: 216,349; xml: 1,584; sh: 330; perl: 114; ansic: 102; makefile: 45
file content (49 lines) | stat: -rw-r--r-- 1,614 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from zipimport import zipimporter
from tempfile import NamedTemporaryFile
import unittest
import sys
import os.path
import java.lang.Package

from test import test_support
from zipfile import ZipFile

class SyspathZipimportTest(unittest.TestCase):
    def setUp(self):
        self.orig_path = sys.path
        sys.path.insert(0, test_support.findfile("syspath_import.jar"))

        # TODO confirm that package is unloaded via a phantom ref or something like that
        
    def tearDown(self):
        sys.path = self.orig_path

    def test_load_class_from_syspath_zip(self):
        from syspathonly import Syspath
        self.assertEquals(Syspath.staticCall(), "result")

    def test_package_defined(self):
        from syspathonly import Syspath
        package = Syspath().class.package
        self.assert_(isinstance(package, java.lang.Package))
        self.assertEquals(package.name, 'syspathonly')

    def test_load_pkg_from_syspath(self):
        import syspathpkg
        self.assertEquals(syspathpkg.__name__, 'syspathpkg')
        self.assert_('syspath_import.jar' in syspathpkg.__file__)
        from syspathpkg import module
        self.assertEquals(module.__name__, 'syspathpkg.module')

class ZipImporterDictTest(unittest.TestCase):
    def test_subclass_assign_attribute(self):
        class A(zipimporter): pass
        path = os.path.abspath('tests/modjy/lib_python_folder/test_modules.zip')
        A(path).somevar = 1

def test_main():
    test_support.run_unittest(SyspathZipimportTest)
    test_support.run_unittest(ZipImporterDictTest)

if __name__ == "__main__":
    test_main()