diff --git a/blogtopoid/blogtopoid.py b/blogtopoid/blogtopoid.py index aed3e67..b94a9b0 100644 --- a/blogtopoid/blogtopoid.py +++ b/blogtopoid/blogtopoid.py @@ -338,4 +338,5 @@ def write_file(filename, content): :param filename: filename to write to :param content: content to write """ - codecs.open(filename, 'w', 'utf-8').write(content) + with codecs.open(filename, 'w', 'utf-8') as afile: + afile.write(content) diff --git a/blogtopoid/test/test_blogtopoid.py b/blogtopoid/test/test_blogtopoid.py index a59df91..fabfe67 100644 --- a/blogtopoid/test/test_blogtopoid.py +++ b/blogtopoid/test/test_blogtopoid.py @@ -66,3 +66,14 @@ class TestHashstore(unittest.TestCase): self.hashstore.hashfile('hashme.txt') ) os.remove('hashme.txt') + + +class TestStaticMethods(unittest.TestCase): + def test_write_file(self): + blogtopoid.write_file('testfilename.txt', '1234') + + with codecs.open('testfilename.txt', 'r', 'utf8') as afile: + contents = afile.read() + self.assertEqual('1234', contents) + + os.remove('testfilename.txt')