diff options
Diffstat (limited to 'cmdtestlib_tests.py')
-rw-r--r-- | cmdtestlib_tests.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/cmdtestlib_tests.py b/cmdtestlib_tests.py index a49cdad..52c72cd 100644 --- a/cmdtestlib_tests.py +++ b/cmdtestlib_tests.py @@ -14,9 +14,12 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. +import os +import shutil +import tempfile import unittest -from cmdtestlib import TestDir +from cmdtestlib import TestDir, cat class TestDirTests(unittest.TestCase): @@ -62,3 +65,22 @@ class TestDirTests(unittest.TestCase): self.assertEqual(td.find_prefixes(['setup', 'foo.setup', 'bar.script']), ['bar', 'foo']) + +class CatTests(unittest.TestCase): + + def setUp(self): + self.tempdir = tempfile.mkdtemp() + + def tearDown(self): + shutil.rmtree(self.tempdir) + + def test_returns_empty_string_for_nonexistent_file(self): + filename = os.path.join(self.tempdir, 'file.txt') + self.assertEqual(cat(filename), '') + + def test_returns_contents_of_file(self): + filename = os.path.join(self.tempdir, 'file.txt') + with open(filename, 'w') as f: + f.write('foobar') + self.assertEqual(cat(filename), 'foobar') + |