Pārlūkot izejas kodu

Test get_asctime.

Chris McDonough 15 gadi atpakaļ
vecāks
revīzija
1ab09e1009

+ 3 - 2
src/supervisor/childutils.py

@@ -38,8 +38,9 @@ def eventdata(payload):
     headers = get_headers(headerinfo)
     headers = get_headers(headerinfo)
     return headers, data
     return headers, data
 
 
-def get_asctime():
-    now = time.time()
+def get_asctime(now=None):
+    if now is None: # for testing
+        now = time.time()
     msecs = (now - long(now)) * 1000
     msecs = (now - long(now)) * 1000
     part1 = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(now))
     part1 = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(now))
     asctime = '%s,%03d' % (part1, msecs)
     asctime = '%s,%03d' % (part1, msecs)

+ 5 - 0
src/supervisor/tests/test_childutils.py

@@ -38,6 +38,11 @@ class ChildUtilsTests(unittest.TestCase):
         self.assertEqual(headers, {'a':'1', 'b':'2'})
         self.assertEqual(headers, {'a':'1', 'b':'2'})
         self.assertEqual(data, 'thedata\n')
         self.assertEqual(data, 'thedata\n')
 
 
+    def test_get_asctime(self):
+        from supervisor.childutils import get_asctime
+        result = get_asctime(2147483647)
+        self.assertEqual(result, '2038-01-18 22:14:07,000')
+
 class TestProcessCommunicationsProtocol(unittest.TestCase):
 class TestProcessCommunicationsProtocol(unittest.TestCase):
     def test_send(self):
     def test_send(self):
         from supervisor.childutils import pcomm
         from supervisor.childutils import pcomm