def test_isfile(self): self.assertTrue(zipio.isfile(os.path.join(TESTDATA, 'test.txt'))) self.assertFalse(zipio.isfile(os.path.join(TESTDATA, 'subdir'))) self.assertRaises(IOError, zipio.isfile, os.path.join(TESTDATA, 'no-such-file')) self.assertFalse(zipio.isfile(os.path.join(TESTDATA, 'zipped.egg'))) self.assertFalse(zipio.isfile(os.path.join(TESTDATA, 'zipped.egg', 'subdir4'))) self.assertTrue(zipio.isfile(os.path.join(TESTDATA, 'zipped.egg', 'test.txt'))) self.assertFalse(zipio.isfile(os.path.join(TESTDATA, 'zipped.egg', 'subdir'))) self.assertRaises(IOError, zipio.isfile, os.path.join(TESTDATA, 'zipped.egg', 'no-such-file')) self.assertTrue(zipio.isfile(os.path.join(TESTDATA, 'zipped.egg', 'subdir2', 'subdir', 'file1.txt')))
def test_package_data(self): p = self.start_app() p.stdin.write('import_module("package2.sub")\n'.encode('latin1')) p.stdin.flush() ln = p.stdout.readline() self.assertEqual(ln.strip(), b"package2.sub") p.stdin.write('import package2.sub\n'.encode('latin1')) p.stdin.write('print(package2.sub.__file__)\n'.encode('latin1')) p.stdin.flush() ln = p.stdout.readline() path = ln.decode('utf-8')[:-1] self.assertTrue(os.path.basename(path) in ['__init__.py', '__init__.pyc', '__init__.pyo']) self.assertTrue(zipio.isfile(path)) path = os.path.join(os.path.dirname(path), 'data.dat') self.assertTrue(zipio.isfile(path) or os.path.isfile(path)) self.assertChecksumsSame()
def test_package_data(self): p = self.start_app() p.stdin.write('import_module("package2.sub")\n'.encode('latin1')) p.stdin.flush() ln = p.stdout.readline() self.assertEqual(ln.strip(), b"package2.sub") p.stdin.write('import package2.sub\n'.encode('latin1')) p.stdin.write('print(package2.sub.__file__)\n'.encode('latin1')) p.stdin.flush() ln = p.stdout.readline() path = ln.decode('utf-8')[:-1] self.assertTrue( os.path.basename(path) in ['__init__.py', '__init__.pyc', '__init__.pyo']) self.assertTrue(zipio.isfile(path)) path = os.path.join(os.path.dirname(path), 'data.dat') self.assertTrue(zipio.isfile(path) or os.path.isfile(path)) self.assertChecksumsSame()
def test_package_data(self): p = self.start_app() p.stdin.write(b'import_module("package2.sub")\n') p.stdin.flush() ln = p.stdout.readline() self.assertEqual(ln.strip(), b"package2.sub") p.stdin.write(b"import package2.sub\n") p.stdin.write(b"print(package2.sub.__file__)\n") p.stdin.flush() ln = p.stdout.readline() path = ln.decode("utf-8")[:-1] self.assertTrue( os.path.basename(path) in ["__init__.py", "__init__.pyc", "__init__.pyo"] ) self.assertTrue(zipio.isfile(path)) path = os.path.join(os.path.dirname(path), "data.dat") self.assertTrue(zipio.isfile(path) or os.path.isfile(path)) self.assertChecksumsSame()
def do_file_exist(filename): return zipio.isfile(filename)