revive FileLoad for the moment - it's used by the web interface.
authorJelmer Vernooij <jelmer@samba.org>
Mon, 22 Nov 2010 22:19:10 +0000 (23:19 +0100)
committerJelmer Vernooij <jelmer@samba.org>
Mon, 22 Nov 2010 22:19:10 +0000 (23:19 +0100)
buildfarm/tests/test_util.py
buildfarm/util.py

index 17bb1615c1c904790cabe52676f0ceb001525162..a727ee288e80953153513d3952621596cf2d7ce7 100755 (executable)
 #   along with this program; if not, write to the Free Software
 #   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
+import os
+import tempfile
 import testtools
+import unittest
 
 from buildfarm import util
 
-class DhmTimeTests(testtools.TestCase):
+class DhmTimeTests(unittest.TestCase):
 
     def test_simple(self):
         self.assertEquals("0s", util.dhm_time(0))
@@ -27,3 +30,23 @@ class DhmTimeTests(testtools.TestCase):
         self.assertEquals("-", util.dhm_time(-20))
         self.assertEquals("1d 3h 1m", util.dhm_time(97265))
         self.assertEquals("3h 1m", util.dhm_time(10865))
+
+
+class LoadTests(testtools.TestCase):
+
+    def test_simple(self):
+        fd, name = tempfile.mkstemp()
+        self.addCleanup(os.remove, name)
+        f = os.fdopen(fd, 'w')
+        f.write("""one
+two
+three\r
+
+for
+""")
+        f.close()
+        l = util.load_list(name)
+        self.assertEquals(4, len(l))
+        self.assertEquals("three", l[2])
+
+
index 70989a1fba166a00a0ad18244713207d3c934353..9d6c8ca497a70ce1f62a1a4716ab705f5e016401 100644 (file)
@@ -32,6 +32,15 @@ def load_list(fname):
     return ret
 
 
+def FileLoad(filename):
+    """read a file into a string"""
+    f = open(filename, 'r')
+    try:
+        return f.read()
+    finally:
+        f.close()
+
+
 def dhm_time(sec):
     """display a time as days, hours, minutes"""
     days = int(sec / (60*60*24));