From 62d0aa159fc046a27bed47e337d787a08f4687d0 Mon Sep 17 00:00:00 2001 From: Sunaina Pai Date: Sat, 17 Mar 2018 14:45:21 +0530 Subject: Add makesite: A simple static site generator --- test/test_path.py | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 test/test_path.py (limited to 'test/test_path.py') 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)) -- cgit v1.2.3