[Git][NTPsec/ntpsec][master] Add unit tests for ntpc module

James Browning gitlab at mg.gitlab.com
Tue Dec 10 00:23:07 UTC 2019



James Browning pushed to branch master at NTPsec / ntpsec


Commits:
d1795ae7 by James Browning at 2019-12-10T00:12:28Z
Add unit tests for ntpc module

Signed-off-by: Richard Laager <rlaager at wiktel.com>

- - - - -


2 changed files:

- + tests/pylib/test_ntpc.py
- tests/wscript


Changes:

=====================================
tests/pylib/test_ntpc.py
=====================================
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+# SPDX-License-Identifier: BSD-2-Clause
+import unittest
+import ntp.ntpc
+
+
+class TestPylibNtpc(unittest.TestCase):
+    lfp_set = [
+        ("0xcfba1ce0.80000000", 1276092000.5,
+         "cfba1ce0.80000000 2010-06-09T14:00:00.500Z"),
+        ("==cfba1ce0.80000000", 1276092000.5,
+         "cfba1ce0.80000000 2010-06-09T14:00:00.500Z"),
+        ]
+
+    def test_statustoa(self):
+        self.assertEqual("leap_add_sec, sync_22, 7 events, no_sys_peer",
+                         ntp.ntpc.statustoa(ntp.ntpc.TYPE_SYS, 0x12345678));
+        self.assertEqual("authenb, reach, sel_sys.peer, 7 events, access_denied",
+                         ntp.ntpc.statustoa(ntp.ntpc.TYPE_PEER, 0x12345678));
+        self.assertEqual("7 events, clk_8",
+                         ntp.ntpc.statustoa(ntp.ntpc.TYPE_CLOCK, 0x12345678));
+
+    def test_lfp(self):
+        for (in_string, to_float, to_string) in self.lfp_set:
+            self.assertEqual(ntp.ntpc.prettydate(in_string), to_string);
+            self.assertAlmostEqual(ntp.ntpc.lfptofloat(in_string), to_float);
+
+
+if __name__ == '__main__':
+    unittest.main()


=====================================
tests/wscript
=====================================
@@ -126,6 +126,7 @@ def build(ctx):
     pytests = ["pylib/test_util.py",
                "pylib/test_agentx.py",
                "pylib/test_agentx_packet.py",
+               "pylib/test_ntpc.py",
                "pylib/test_packet.py",
                "pylib/test_statfiles.py"]
 



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/d1795ae7f2f2b18540e8be3f256651a6b2dd078d

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/d1795ae7f2f2b18540e8be3f256651a6b2dd078d
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20191210/3773731c/attachment-0001.htm>


More information about the vc mailing list