Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes
test.test_pkgutil.PkgutilTests Class Reference

List of all members.

Public Member Functions

def setUp
def tearDown
def test_getdata_filesys
def test_getdata_zipfile

Public Attributes

 dirname

Detailed Description

Definition at line 14 of file test_pkgutil.py.


Member Function Documentation

Definition at line 16 of file test_pkgutil.py.

00016 
00017     def setUp(self):
00018         self.dirname = tempfile.mkdtemp()
00019         sys.path.insert(0, self.dirname)

Here is the caller graph for this function:

Definition at line 20 of file test_pkgutil.py.

00020 
00021     def tearDown(self):
00022         del sys.path[0]
00023         shutil.rmtree(self.dirname)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 24 of file test_pkgutil.py.

00024 
00025     def test_getdata_filesys(self):
00026         pkg = 'test_getdata_filesys'
00027 
00028         # Include a LF and a CRLF, to test that binary data is read back
00029         RESOURCE_DATA = b'Hello, world!\nSecond line\r\nThird line'
00030 
00031         # Make a package with some resources
00032         package_dir = os.path.join(self.dirname, pkg)
00033         os.mkdir(package_dir)
00034         # Empty init.py
00035         f = open(os.path.join(package_dir, '__init__.py'), "wb")
00036         f.close()
00037         # Resource files, res.txt, sub/res.txt
00038         f = open(os.path.join(package_dir, 'res.txt'), "wb")
00039         f.write(RESOURCE_DATA)
00040         f.close()
00041         os.mkdir(os.path.join(package_dir, 'sub'))
00042         f = open(os.path.join(package_dir, 'sub', 'res.txt'), "wb")
00043         f.write(RESOURCE_DATA)
00044         f.close()
00045 
00046         # Check we can read the resources
00047         res1 = pkgutil.get_data(pkg, 'res.txt')
00048         self.assertEqual(res1, RESOURCE_DATA)
00049         res2 = pkgutil.get_data(pkg, 'sub/res.txt')
00050         self.assertEqual(res2, RESOURCE_DATA)
00051 
00052         del sys.modules[pkg]

Here is the call graph for this function:

Definition at line 53 of file test_pkgutil.py.

00053 
00054     def test_getdata_zipfile(self):
00055         zip = 'test_getdata_zipfile.zip'
00056         pkg = 'test_getdata_zipfile'
00057 
00058         # Include a LF and a CRLF, to test that binary data is read back
00059         RESOURCE_DATA = b'Hello, world!\nSecond line\r\nThird line'
00060 
00061         # Make a package with some resources
00062         zip_file = os.path.join(self.dirname, zip)
00063         z = zipfile.ZipFile(zip_file, 'w')
00064 
00065         # Empty init.py
00066         z.writestr(pkg + '/__init__.py', "")
00067         # Resource files, res.txt, sub/res.txt
00068         z.writestr(pkg + '/res.txt', RESOURCE_DATA)
00069         z.writestr(pkg + '/sub/res.txt', RESOURCE_DATA)
00070         z.close()
00071 
00072         # Check we can read the resources
00073         sys.path.insert(0, zip_file)
00074         res1 = pkgutil.get_data(pkg, 'res.txt')
00075         self.assertEqual(res1, RESOURCE_DATA)
00076         res2 = pkgutil.get_data(pkg, 'sub/res.txt')
00077         self.assertEqual(res2, RESOURCE_DATA)
00078 
00079         names = []
00080         for loader, name, ispkg in pkgutil.iter_modules([zip_file]):
00081             names.append(name)
00082         self.assertEqual(names, ['test_getdata_zipfile'])
00083 
00084         del sys.path[0]
00085 
00086         del sys.modules[pkg]

Here is the call graph for this function:


Member Data Documentation

Definition at line 17 of file test_pkgutil.py.


The documentation for this class was generated from the following file: