summaryrefslogtreecommitdiff
path: root/test/test_path.py
diff options
context:
space:
mode:
authorSunaina Pai <sunainapai.in@gmail.com>2018-03-17 14:45:21 +0530
committerSunaina Pai <sunainapai.in@gmail.com>2018-03-17 14:45:21 +0530
commit62d0aa159fc046a27bed47e337d787a08f4687d0 (patch)
treec1162f14377890c290d2ad114b3892cbb9848975 /test/test_path.py
Add makesite: A simple static site generator
Diffstat (limited to 'test/test_path.py')
-rw-r--r--test/test_path.py78
1 files changed, 78 insertions, 0 deletions
diff --git a/test/test_path.py b/test/test_path.py
new file mode 100644
index 0000000..91e76e8
--- /dev/null
+++ b/test/test_path.py
@@ -0,0 +1,78 @@
+import unittest
+import os
+import shutil
+
+from test import path
+
+class PathTest(unittest.TestCase):
+ def test_temppath(self):
+ self.assertTrue(path.temppath())
+
+ def test_move_existing_file(self):
+ src = os.path.join(path.temppath(), 'foo.txt')
+ dst = os.path.join(path.temppath(), 'bar.txt')
+ with open(src, 'w') as f:
+ f.write('foo')
+
+ path.move(src, dst)
+ self.assertFalse(os.path.isfile(src))
+ self.assertTrue(os.path.isfile(dst))
+
+ with open(dst) as f:
+ text = f.read()
+
+ os.remove(dst)
+
+ self.assertEqual(text, 'foo')
+
+ def test_move_missing_file(self):
+ src = os.path.join(path.temppath(), 'foo.txt')
+ dst = os.path.join(path.temppath(), 'bar.txt')
+ path.move(src, dst)
+ self.assertFalse(os.path.isfile(src))
+ self.assertFalse(os.path.isfile(dst))
+
+ def test_move_file_cleanup(self):
+ src = os.path.join(path.temppath(), 'foo.txt')
+ dst = os.path.join(path.temppath(), 'bar.txt')
+ with open(dst, 'w') as f:
+ f.write('foo')
+ path.move(src, dst)
+ self.assertFalse(os.path.isfile(src))
+ self.assertFalse(os.path.isfile(dst))
+
+ def test_move_existing_dir(self):
+ src = os.path.join(path.temppath(), 'foo')
+ srcf = os.path.join(src, 'foo.txt')
+ dst = os.path.join(path.temppath(), 'bar')
+ dstf = os.path.join(dst, 'foo.txt')
+
+ os.makedirs(src)
+ with open(srcf, 'w') as f:
+ f.write('foo')
+
+ path.move(src, dst)
+ self.assertFalse(os.path.isdir(src))
+ self.assertTrue(os.path.isdir(dst))
+
+ with open(dstf) as f:
+ text = f.read()
+
+ shutil.rmtree(dst)
+
+ self.assertEqual(text, 'foo')
+
+ def test_move_missing_dir(self):
+ src = os.path.join(path.temppath(), 'foo')
+ dst = os.path.join(path.temppath(), 'bar')
+ path.move(src, dst)
+ self.assertFalse(os.path.isdir(src))
+ self.assertFalse(os.path.isdir(dst))
+
+ def test_move_dir_cleanup(self):
+ src = os.path.join(path.temppath(), 'foo')
+ dst = os.path.join(path.temppath(), 'bar')
+ os.makedirs(dst)
+ path.move(src, dst)
+ self.assertFalse(os.path.isdir(src))
+ self.assertFalse(os.path.isdir(dst))