summaryrefslogtreecommitdiff
path: root/cmdtestlib_tests.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2012-04-12 20:59:05 +0100
committerLars Wirzenius <liw@liw.fi>2012-04-12 20:59:05 +0100
commit59468a2002aa26808a83fd2fb2db0e4e2c83575f (patch)
tree14c6d40184d6b2996d8adb368b2e2aef2f8f5bda /cmdtestlib_tests.py
parentd340738d97b7dbc2b0a0a30d05c68e85cc6033b5 (diff)
downloadcmdtest-59468a2002aa26808a83fd2fb2db0e4e2c83575f.tar.gz
Move cat method to cmdtestlib
Diffstat (limited to 'cmdtestlib_tests.py')
-rw-r--r--cmdtestlib_tests.py24
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')
+