def testTmpdir(self): """Verify `ctx.tmpdir`""" with ctx.tmpdir() as path: path_copy = path self.assertExists(path) self.assertNotExists(path_copy)
def testAddPath(self): """Verify `ctx.add_path`""" # Create a temp directory with ctx.tmpdir() as path: # The temp dir should not be in the path yet. self.assertNotIn(path, sys.path) with ctx.add_path(path): # Now it should be in the path self.assertIn(path, sys.path) # After exiting the context, it should be gone again self.assertNotIn(path, sys.path)
def testChdir(self): """Verify `ctx.chdir`""" with ctx.tmpdir() as path: orig_dir = os.getcwd() # Make sure we're not in the new tmpdir. This should be impossible. self.assertNotEquals(orig_dir, path) with ctx.chdir(path): # Make sure we changed correctly self.assertEquals(os.getcwd(), path) # Make sure we're not there anymore self.assertNotEquals(os.getcwd(), path) # Make sure we returned to the original location self.assertEquals(os.getcwd(), orig_dir)
def testChdir(self): """Verify `ctx.chdir`""" with ctx.tmpdir() as path: orig_dir = os.getcwd() # Make sure we're not in the new tmpdir. This should be impossible. self.assertDifferentPath(orig_dir, path) with ctx.chdir(path): # Make sure we changed correctly self.assertSamePath(os.getcwd(), path) # Make sure we're not there anymore self.assertDifferentPath(os.getcwd(), path) # Make sure we returned to the original location self.assertSamePath(os.getcwd(), orig_dir)