def test_download_isolated(self): out_dir = None try: out_dir = tempfile.mkdtemp() # Store the required files. self._store('file1.txt') self._store('repeated_files.py') # Loads an arbitrary .isolated on the file system. isolated = os.path.join(self.data_dir, 'download.isolated') out, err, returncode = self._run( self._generate_args_with_isolated(isolated) + ['--download', out_dir]) expected_output = ( '.isolated files successfully downloaded and setup in ' '%s\nTo run this test please run the command %s from ' 'the directory %s\n' % (out_dir, [sys.executable, u'repeated_files.py' ], out_dir + os.path.sep)) if not VERBOSE: # On Windows, it'll warn that a symlink is ignored to stderr. if sys.platform != 'win32': self.assertEqual('', err) self.assertEqual(expected_output, out) self.assertEqual(0, returncode) # Ensure the correct files have been placed in the temp directory. expected = [ 'file1.txt', os.path.join('new_folder', 'file1.txt'), 'repeated_files.py', ] if sys.platform != 'win32': expected.append('file1_symlink.txt') actual = list_files_tree(out_dir) self.assertEqual(sorted(expected), sorted(actual)) if sys.platform != 'win32': self.assertTrue( os.path.lexists(os.path.join(out_dir, 'file1_symlink.txt'))) finally: if out_dir: run_isolated.rmtree(out_dir)
def test_download_isolated(self): out_dir = None try: out_dir = tempfile.mkdtemp() # Store the required files. self._store('file1.txt') self._store('repeated_files.py') # Loads an arbitrary .isolated on the file system. isolated = os.path.join(self.data_dir, 'download.isolated') out, err, returncode = self._run( self._generate_args_with_isolated(isolated) + ['--download', out_dir]) expected_output = ('.isolated files successfully downloaded and setup in ' '%s\nTo run this test please run the command %s from ' 'the directory %s\n' % (out_dir, [sys.executable, u'repeated_files.py'], out_dir + os.path.sep)) if not VERBOSE: # On Windows, it'll warn that a symlink is ignored to stderr. if sys.platform != 'win32': self.assertEqual('', err) self.assertEqual(expected_output, out) self.assertEqual(0, returncode) # Ensure the correct files have been placed in the temp directory. expected = [ 'file1.txt', os.path.join('new_folder', 'file1.txt'), 'repeated_files.py', ] if sys.platform != 'win32': expected.append('file1_symlink.txt') actual = list_files_tree(out_dir) self.assertEqual(sorted(expected), sorted(actual)) if sys.platform != 'win32': self.assertTrue( os.path.lexists(os.path.join(out_dir, 'file1_symlink.txt'))) finally: if out_dir: run_isolated.rmtree(out_dir)
def test_rmtree_win(self): # Mock our sleep for faster test case execution. sleeps = [] self.mock(time, 'sleep', sleeps.append) self.mock(sys, 'stderr', StringIO.StringIO()) # Open a child process, so the file is locked. subdir = os.path.join(self.tempdir, 'to_be_deleted') os.mkdir(subdir) script = 'import time; open(\'a\', \'w\'); time.sleep(60)' proc = subprocess.Popen([sys.executable, '-c', script], cwd=subdir) try: # Wait until the file exist. while not os.path.isfile(os.path.join(subdir, 'a')): self.assertEqual(None, proc.poll()) run_isolated.rmtree(subdir) self.assertEqual([2, 4, 2], sleeps) # sys.stderr.getvalue() would return a fair amount of output but it is # not completely deterministic so we're not testing it here. finally: proc.wait()
def tearDown(self): run_isolated.rmtree(self.tempdir) super(RunIsolatedTest, self).tearDown()
def tearDown(self): try: run_isolated.rmtree(self.tempdir) finally: super(IsolateFormatTmpDirTest, self).tearDown()