From 59468a2002aa26808a83fd2fb2db0e4e2c83575f Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Thu, 12 Apr 2012 20:59:05 +0100 Subject: Move cat method to cmdtestlib --- cmdtestlib_tests.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'cmdtestlib_tests.py') 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 . +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') + -- cgit v1.2.1