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_file_io.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 test/test_file_io.py (limited to 'test/test_file_io.py') diff --git a/test/test_file_io.py b/test/test_file_io.py new file mode 100644 index 0000000..3760956 --- /dev/null +++ b/test/test_file_io.py @@ -0,0 +1,39 @@ +import unittest +import os +import shutil + +import makesite +from test import path + + +class FileIOTest(unittest.TestCase): + """Tests for file I/O functions.""" + + def test_fread(self): + text = 'foo\nbar\n' + filepath = path.temppath('foo.txt') + with open(filepath, 'w') as f: + f.write(text) + text_read = makesite.fread(filepath) + os.remove(filepath) + self.assertEqual(text_read, text) + + def test_fwrite(self): + text = 'baz\nqux\n' + filepath = path.temppath('foo.txt') + makesite.fwrite(filepath, text) + with open(filepath) as f: + text_read = f.read() + os.remove(filepath) + self.assertEqual(text_read, text) + + def test_fwrite_makedir(self): + text = 'baz\nqux\n' + dirpath = path.temppath('foo', 'bar') + filepath = os.path.join(dirpath, 'foo.txt') + makesite.fwrite(filepath, text) + with open(filepath) as f: + text_read = f.read() + self.assertTrue(os.path.isdir(dirpath)) + shutil.rmtree(path.temppath('foo')) + self.assertEqual(text_read, text) -- cgit v1.2.3