[Git][NTPsec/ntpsec][master] 4 commits: jigs.py: Remove unnecessary shebang

Richard Laager (@rlaager) gitlab at mg.gitlab.com
Tue Mar 30 22:08:11 UTC 2021



Richard Laager pushed to branch master at NTPsec / ntpsec


Commits:
01c29ffa by Richard Laager at 2021-03-28T00:14:42+00:00
jigs.py: Remove unnecessary shebang

This file is not designed to be directly executed.

Refs #670

- - - - -
b566e38a by Richard Laager at 2021-03-28T00:14:42+00:00
Remove shebangs from test/pylib/*

These are not executed directly, but are instead run explicitly under
the target Python.

Refs #670

- - - - -
9b2e1ce2 by Richard Laager at 2021-03-28T00:14:42+00:00
bin_test: Refactor version

This is a pure refactoring step to simplify the upcoming commit.

Refs #670

- - - - -
caa4aba1 by Richard Laager at 2021-03-28T00:14:42+00:00
bin_test: Run Python tests under the target Python

In a Python cross scenario, the tests need to run under the target
Python, not the waf Python in order to be able to load the module (which
was compiled for the target Python).

Fixes #670

- - - - -


8 changed files:

- tests/pylib/jigs.py
- tests/pylib/test_agentx.py
- tests/pylib/test_agentx_packet.py
- tests/pylib/test_ntpc.py
- tests/pylib/test_packet.py
- tests/pylib/test_statfiles.py
- tests/pylib/test_util.py
- wafhelpers/bin_test.py


Changes:

=====================================
tests/pylib/jigs.py
=====================================
@@ -1,4 +1,3 @@
-#! /usr/bin/env python
 # -*- coding: utf-8 -*-
 
 from __future__ import print_function, division


=====================================
tests/pylib/test_agentx.py
=====================================
@@ -1,4 +1,3 @@
-#! /usr/bin/env python
 # -*- coding: utf-8 -*-
 
 import ntp.agentx as AX


=====================================
tests/pylib/test_agentx_packet.py
=====================================
@@ -1,4 +1,3 @@
-#! /usr/bin/env python
 # -*- coding: utf-8 -*-
 
 import unittest


=====================================
tests/pylib/test_ntpc.py
=====================================
@@ -1,4 +1,3 @@
-#! /usr/bin/env python
 # -*- coding: utf-8 -*-
 # SPDX-License-Identifier: BSD-2-Clause
 import unittest


=====================================
tests/pylib/test_packet.py
=====================================
@@ -1,4 +1,3 @@
-#! /usr/bin/env python
 # -*- coding: utf-8 -*-
 
 from __future__ import print_function, division


=====================================
tests/pylib/test_statfiles.py
=====================================
@@ -1,4 +1,3 @@
-#! /usr/bin/env python
 # -*- coding: utf-8 -*-
 
 import unittest


=====================================
tests/pylib/test_util.py
=====================================
@@ -1,4 +1,3 @@
-#! /usr/bin/env python
 # -*- coding: utf-8 -*-
 
 from __future__ import print_function


=====================================
wafhelpers/bin_test.py
=====================================
@@ -6,36 +6,32 @@ import sys
 import waflib.Context
 import waflib.Logs
 import waflib.Utils
-sys.path.insert(0, "%s/main/tests/pylib" % waflib.Context.out_dir)
-import ntp.util
 
-version = ntp.util.stdversion()
 Popen = waflib.Utils.subprocess.Popen
 
 cmd_map = {
-    ("main/ntpclients/ntpleapfetch", "--version"): "ntpleapfetch %s\n"
-                                                   % version,
-    ("main/ntpd/ntpd", "--version"): "ntpd %s\n" % version,
-    ("main/ntpfrob/ntpfrob", "-V"): "ntpfrob %s\n" % version,
-    ("main/ntptime/ntptime", "-V"): "ntptime %s\n" % version
+    ("main/ntpclients/ntpleapfetch", "--version"): "ntpleapfetch %s\n",
+    ("main/ntpd/ntpd", "--version"): "ntpd %s\n",
+    ("main/ntpfrob/ntpfrob", "-V"): "ntpfrob %s\n",
+    ("main/ntptime/ntptime", "-V"): "ntptime %s\n"
 }
 cmd_map_python = {
-    ("main/ntpclients/ntpdig", "--version"): "ntpdig %s\n" % version,
-    ("main/ntpclients/ntpkeygen", "--version"): "ntpkeygen %s\n" % version,
-    ("main/ntpclients/ntpq", "--version"): "ntpq %s\n" % version,
-    ("main/ntpclients/ntpsnmpd", "--version"): "ntpsnmpd %s\n" % version,
-    ("main/ntpclients/ntpsweep", "--version"): "ntpsweep %s\n" % version,
-    ("main/ntpclients/ntptrace", "--version"): "ntptrace %s\n" % version,
-    ("main/ntpclients/ntpwait", "--version"): "ntpwait %s\n" % version
+    ("main/ntpclients/ntpdig", "--version"): "ntpdig %s\n",
+    ("main/ntpclients/ntpkeygen", "--version"): "ntpkeygen %s\n",
+    ("main/ntpclients/ntpq", "--version"): "ntpq %s\n",
+    ("main/ntpclients/ntpsnmpd", "--version"): "ntpsnmpd %s\n",
+    ("main/ntpclients/ntpsweep", "--version"): "ntpsweep %s\n",
+    ("main/ntpclients/ntptrace", "--version"): "ntptrace %s\n",
+    ("main/ntpclients/ntpwait", "--version"): "ntpwait %s\n"
 }
 # Need argparse
 cmd_map_python_argparse = {
-    ("main/ntpclients/ntplogtemp", "--version"): "ntplogtemp %s\n" % version,
-    ("main/ntpclients/ntpviz", "--version"): "ntpviz %s\n" % version,
+    ("main/ntpclients/ntplogtemp", "--version"): "ntplogtemp %s\n",
+    ("main/ntpclients/ntpviz", "--version"): "ntpviz %s\n",
 }
 # Need python curses
 cmd_map_python_curses = {
-    ("main/ntpclients/ntpmon", "--version"): "ntpmon %s\n" % version,
+    ("main/ntpclients/ntpmon", "--version"): "ntpmon %s\n",
 }
 
 test_logs = []
@@ -52,16 +48,17 @@ def bin_test_summary(ctx):
         waflib.Logs.pprint(i[0], i[1])
 
 
-def run(cmd, expected, pythonic):
+def run(cmd, expected, python=None):
     """Run an individual test."""
+
     prefix = "running: " + " ".join(cmd)
 
     if not os.path.exists("%s/%s" % (waflib.Context.out_dir, cmd[0])):
         addLog("YELLOW", prefix + " SKIPPING (does not exist)")
         return False
 
-    if pythonic:
-        cmd = [sys.executable] + list(cmd)
+    if python:
+        cmd = python + list(cmd)
     p = Popen(cmd, env={'PYTHONPATH': '%s/main/tests/pylib' %
                         waflib.Context.out_dir},
               universal_newlines=True,
@@ -88,6 +85,18 @@ def cmd_bin_test(ctx):
     """Run a suite of binary tests."""
     fails = 0
 
+    cmd = ctx.env['PYTHON'] + ['-c',
+        'from __future__ import print_function;'
+        'import ntp.util;'
+        'print(ntp.util.stdversion())']
+    p = waflib.Utils.subprocess.Popen(cmd, env={'PYTHONPATH': '%s/main/tests/pylib' %
+                                                 waflib.Context.out_dir},
+                         universal_newlines=True,
+                         stdin=waflib.Utils.subprocess.PIPE,
+                         stdout=waflib.Utils.subprocess.PIPE,
+                         stderr=waflib.Utils.subprocess.PIPE, cwd=waflib.Context.out_dir)
+    version = p.communicate()[0].rstrip()
+
     if ctx.env['PYTHON_ARGPARSE']:
         cmd_map_python.update(cmd_map_python_argparse)
 
@@ -95,11 +104,11 @@ def cmd_bin_test(ctx):
         cmd_map_python.update(cmd_map_python_curses)
 
     for cmd in sorted(cmd_map):
-        if not run(cmd, cmd_map[cmd], False):
+        if not run(cmd, cmd_map[cmd] % version):
             fails += 1
 
     for cmd in sorted(cmd_map_python):
-        if not run(cmd, cmd_map_python[cmd], True):
+        if not run(cmd, cmd_map_python[cmd] % version, ctx.env['PYTHON']):
             fails += 1
 
     if 1 == fails:



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/b9a12069a2a2eecac309f5668a5be8df966ca74b...caa4aba1daaa3b39e254a19f397fa2f3262e5099

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/compare/b9a12069a2a2eecac309f5668a5be8df966ca74b...caa4aba1daaa3b39e254a19f397fa2f3262e5099
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/20210330/3a58e713/attachment-0001.htm>


More information about the vc mailing list