def test_as_fn(self): "Should work as a callable" nix.cd('/tmp') cwd = os.getcwd() if sys.platform == 'darwin': cwd = cwd.replace('/private', '') self.assertEqual('/tmp', cwd)
def test_accepts_path(self): "Should Duck-type with Path objects" nix.cd(Path('/tmp')) cwd = os.getcwd() if sys.platform == 'darwin': cwd = cwd.replace('/private', '') self.assertEqual('/tmp', cwd)
def test_contextmanager(self): "Should work as a contextmanager" with nix.cd('/tmp') as path: cwd = os.getcwd() if sys.platform == 'darwin': cwd = cwd.replace('/private', '') self.assertEqual('/tmp', cwd) self.assertIsInstance(path, Path) self.assertEqual('/tmp', path) self.assertEqual(self.startdir, os.getcwd())
def test_contextmanager_raises(self): "Should propagate exceptions" with self.assertRaises(RuntimeError): with nix.cd('/tmp'): raise RuntimeError('!') self.assertEqual(self.startdir, os.getcwd())
def cd(self, target): return nix.cd(target)