def test_running_from_zip(self): # Test assumes that it runs from a normal checkout, not a zip. self.assertFalse(zip_package.is_zipped_module(sys.modules[__name__])) self.assertIsNone(zip_package.get_module_zip_archive(sys.modules[__name__])) self.assertTrue(os.path.abspath( zip_package.get_main_script_path()).startswith(ROOT_DIR)) # Build executable zip that calls same functions. pkg = zip_package.ZipPackage(self.temp_dir) pkg.add_directory(os.path.join(ROOT_DIR, 'utils'), 'utils') pkg.add_buffer('__main__.py', '\n'.join([ 'import sys', '', 'from utils import zip_package', '', 'print zip_package.is_zipped_module(sys.modules[__name__])', 'print zip_package.get_module_zip_archive(sys.modules[__name__])', 'print zip_package.get_main_script_path()', ])) zip_file = os.path.join(self.temp_dir, 'out.zip') pkg.zip_into_file(zip_file) # Run the zip, validate results. actual = check_output([sys.executable, zip_file]).strip().splitlines() self.assertEqual(['True', zip_file, zip_file], actual)
def test_running_from_zip(self): # Test assumes that it runs from a normal checkout, not a zip. self.assertFalse(zip_package.is_zipped_module(sys.modules[__name__])) self.assertIsNone( zip_package.get_module_zip_archive(sys.modules[__name__])) self.assertTrue( os.path.abspath(zip_package.get_main_script_path()).startswith( test_env.CLIENT_DIR)) # Build executable zip that calls same functions. pkg = zip_package.ZipPackage(self.temp_dir) pkg.add_directory(os.path.join(test_env.CLIENT_DIR, 'utils'), 'utils') pkg.add_buffer( '__main__.py', b'\n'.join([ b'import sys', b'', b'from utils import zip_package', b'', b'print(zip_package.is_zipped_module(sys.modules[__name__]))', b'print(zip_package.get_module_zip_archive(sys.modules[__name__]))', b'print(zip_package.get_main_script_path())', ])) zip_file = os.path.join(self.temp_dir, 'out.zip') pkg.zip_into_file(zip_file) # Run the zip, validate results. actual = check_output([sys.executable, zip_file]).strip().splitlines() self.assertEqual(['True', zip_file, zip_file], actual)
def test_running_from_zip(self): # Test assumes that it runs from a normal checkout, not a zip. self.assertFalse(zip_package.is_zipped_module(sys.modules[__name__])) self.assertIsNone(zip_package.get_module_zip_archive(sys.modules[__name__])) self.assertTrue(os.path.abspath( zip_package.get_main_script_path()).startswith(ROOT_DIR)) # Build executable zip that calls same functions. pkg = zip_package.ZipPackage(self.temp_dir) pkg.add_directory(os.path.join(ROOT_DIR, 'utils'), 'utils') pkg.add_buffer('__main__.py', '\n'.join([ 'import sys', '', 'from utils import zip_package', '', 'print zip_package.is_zipped_module(sys.modules[__name__])', 'print zip_package.get_module_zip_archive(sys.modules[__name__])', 'print zip_package.get_main_script_path()', ])) zip_file = os.path.join(self.temp_dir, 'out.zip') pkg.zip_into_file(zip_file) # Run the zip, validate results. proc = subprocess.Popen( [sys.executable, zip_file], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = proc.communicate() actual = out.strip().splitlines() expected = ['True', zip_file, zip_file,] self.assertEqual(err, '') self.assertEqual(actual, expected)