def test_recursive_contents(self): """ This was caused by ending up with a Path as _value, not catching it in __init__. """ p = Path(self.tdir) + 'some.txt' p.touch() p2 = Path(p) self.assertEqual('', p2.contents)
class CPTestCase(unittest.TestCase): def setUp(self): self.tdir = Path(tempfile.mkdtemp()) def tearDown(self): if os.path.exists(self.tdir): shutil.rmtree(self.tdir) def test_cp_file(self): "Copy self to dest" f1 = self.tdir / 'one.txt' f2 = self.tdir + 'two.txt' f1 << 'Contents!' nix.cp(f1, f2) self.assertTrue(filecmp.cmp(f1, f2, False)) def test_cp_dir(self): "Is a no-op" self.tdir.mkdir('this') p = self.tdir / 'that' nix.cp(self.tdir / 'this', p) self.assertFalse(p) def test_cp_file_recursive(self): "Recursive does nothing" f1 = self.tdir / 'one.txt' f2 = self.tdir + 'two.txt' f1 << 'Contents!' nix.cp(f1, f2, recursive=True) self.assertTrue(filecmp.cmp(f1, f2, False)) def test_cp_dir_recursive(self): "Should copy the tree" d1 = self.tdir / 'this' d2 = self.tdir / 'that' d1.touch('one.txt', 'two.txt') self.tdir.mkdir('this') nix.cp(d1, d2, recursive=True) self.assertEqual([], filecmp.dircmp(d1, d2).diff_files) def test_cp_nonexistant(self): "Should raise" with self.assertRaises(exceptions.DoesNotExistError): nix.cp(self.tdir + 'whatever', self.tdir + 'whateverer') def test_cp_target_exists(self): "Should raise" with self.assertRaises(exceptions.ExistsError): self.tdir.touch('whatever', 'whateverer') nix.cp(self.tdir + 'whatever', self.tdir + 'whateverer')
class CPTestCase(unittest.TestCase): def setUp(self): self.tdir = Path(tempfile.mkdtemp()) def tearDown(self): if os.path.exists(self.tdir): shutil.rmtree(self.tdir) def test_cp_file(self): "Copy self to dest" f1 = self.tdir / 'one.txt' f2 = self.tdir + 'two.txt' f1 << 'Contents!' nix.cp(f1, f2) self.assertTrue(filecmp.cmp(f1, f2, False)) def test_cp_dir(self): "Is a no-op" self.tdir.mkdir('this') p = self.tdir / 'that' nix.cp(self.tdir / 'this', p) self.assertFalse(p) def test_cp_file_recursive(self): "Recursive does nothing" f1 = self.tdir / 'one.txt' f2 = self.tdir + 'two.txt' f1 << 'Contents!' nix.cp(f1, f2, recursive=True) self.assertTrue(filecmp.cmp(f1, f2, False)) def test_cp_dir_recursive(self): "Should copy the tree" d1 = self.tdir / 'this' d2 = self.tdir / 'that' d1.touch('one.txt', 'two.txt') self.tdir.mkdir('this') nix.cp(d1, d2, recursive=True) self.assertEqual([], filecmp.dircmp(d1, d2).diff_files) def test_cp_nonexistant(self): "Should raise" with self.assertRaises(exceptions.DoesNotExistError): nix.cp(self.tdir + 'whatever', self.tdir + 'whateverer') def test_cp_target_exists(self): "Should raise" with self.assertRaises(exceptions.ExistsError): self.tdir.touch('whatever', 'whateverer') nix.cp(self.tdir + 'whatever', self.tdir + 'whateverer')
def test_ln_dest_exists(self): "Raise if dest exists" dest = Path(self.tdir) + '/hardlink' dest.touch() with self.assertRaises(exceptions.ExistsError): nix.ln(self.src, dest)
def test_ln_dest_exists(self): "Raise if dest exists" dest = Path(self.tdir) + '/hardlink' dest.touch() with self.assertRaises(exceptions.ExistsError): nix.ln(self.src, dest)