summaryrefslogtreecommitdiff
path: root/selftest/tests
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2012-03-05 04:05:35 +0100
committerJelmer Vernooij <jelmer@samba.org>2012-03-05 05:42:19 +0100
commit53a147d1c0c54fe94ac21f25088fd874d1300102 (patch)
tree55a72d078a35952894d00e3350c451ea5ccff820 /selftest/tests
parentf26b40a92553863bc0da39918ff19bf21199c608 (diff)
downloadsamba-53a147d1c0c54fe94ac21f25088fd874d1300102.tar.gz
samba-53a147d1c0c54fe94ac21f25088fd874d1300102.tar.bz2
samba-53a147d1c0c54fe94ac21f25088fd874d1300102.zip
selftest.run: Factor out read_testlist_file and open_file_or_pipe.
Autobuild-User: Jelmer Vernooij <jelmer@samba.org> Autobuild-Date: Mon Mar 5 05:42:19 CET 2012 on sn-devel-104
Diffstat (limited to 'selftest/tests')
-rw-r--r--selftest/tests/test_testlist.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/selftest/tests/test_testlist.py b/selftest/tests/test_testlist.py
index cd44d46238..4474d0aa07 100644
--- a/selftest/tests/test_testlist.py
+++ b/selftest/tests/test_testlist.py
@@ -19,13 +19,18 @@
"""Tests for selftest.testlist."""
+import os
+import tempfile
+
from selftest.tests import TestCase
from selftest.testlist import (
RestrictedTestManager,
find_in_list,
+ open_file_or_pipe,
read_test_regexes,
read_testlist,
+ read_testlist_file,
)
from cStringIO import StringIO
@@ -100,3 +105,44 @@ class RestrictedTestManagerTests(TestCase):
def test_run_nomatch(self):
mgr = RestrictedTestManager(["foo.bar"])
self.assertEquals([], mgr.should_run_testsuite("foo.blie.bla"))
+
+
+class OpenFileOrPipeTests(TestCase):
+
+ def test_regular_file(self):
+ (fd, p) = tempfile.mkstemp()
+ self.addCleanup(os.remove, p)
+ f = os.fdopen(fd, 'w')
+ try:
+ f.write('data\nbla\n')
+ finally:
+ f.close()
+ f = open_file_or_pipe(p, 'r')
+ try:
+ self.assertEquals("data\nbla\n", f.read())
+ finally:
+ f.close()
+
+ def test_pipe(self):
+ f = open_file_or_pipe('echo foo|', 'r')
+ try:
+ self.assertEquals("foo\n", f.read())
+ finally:
+ f.close()
+
+
+class ReadTestListFileTests(TestCase):
+
+ def test_regular_file(self):
+ (fd, p) = tempfile.mkstemp()
+ self.addCleanup(os.remove, p)
+ f = os.fdopen(fd, 'w')
+ try:
+ f.write('noise\n-- TEST --\ndata\nenv\ncmd\n')
+ finally:
+ f.close()
+ outf = StringIO()
+ self.assertEquals(
+ [('data', 'env', 'cmd', False, False)],
+ list(read_testlist_file(p, outf)))
+ self.assertEquals("noise\n", outf.getvalue())