gpsd-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gpsd-dev] [PATCH 2/3] Makes gpsfake -T take -S into account.


From: Fred Wright
Subject: [gpsd-dev] [PATCH 2/3] Makes gpsfake -T take -S into account.
Date: Thu, 3 Mar 2016 19:01:03 -0800

This makes it possible to view the "slow" as well as the normal
WRITE_PAD values with gpsfake -T, without having to look at the source
code.  It adds a new GetDelay() function to fake.py, which returns the
proper delay value, taking into account both the possible environment
variable and the "slow" option.  This is now used for all hree uses of
WRITE_PAD.

Because the environment override is now part of the function, the
WRITE_PAD constant is no longer modified by the environment value, but
instead reflects the platform default.

TESTED:
Ran the full set of regression tests, with both default and acceptably
shortened WRITE_PAD.  Also verified that a zero value causes trouble
(OSX), and that adding -S to the zero value makes it work.
---
 gps/fake.py | 21 +++++++++++++--------
 gpsfake     |  2 +-
 2 files changed, 14 insertions(+), 9 deletions(-)

diff --git a/gps/fake.py b/gps/fake.py
index 5ba980b..cadd68d 100644
--- a/gps/fake.py
+++ b/gps/fake.py
@@ -96,10 +96,6 @@ elif sys.platform.startswith("darwin"):
 else:
     WRITE_PAD = 0.004
 
-# Make it easier to test pad values
-if os.getenv("WRITE_PAD"):
-    WRITE_PAD = eval(os.getenv("WRITE_PAD"))
-
 # Additional delays in slow mode
 WRITE_PAD_SLOWDOWN = 0.01
 
@@ -107,6 +103,17 @@ WRITE_PAD_SLOWDOWN = 0.01
 TEST_TIMEOUT = 60
 
 
+def GetDelay(slow=False):
+    "Get appropriate per-line delay."
+    delay = WRITE_PAD
+    # Make it easier to test pad values
+    if os.getenv("WRITE_PAD"):
+        delay = eval(os.getenv("WRITE_PAD"))
+    if slow:
+        delay += WRITE_PAD_SLOWDOWN
+    return delay
+
+
 class TestLoadError(exceptions.Exception):
     def __init__(self, msg):
         exceptions.Exception.__init__(self)
@@ -126,9 +133,7 @@ class TestLoad:
         self.type = None
         self.sourcetype = "pty"
         self.serial = None
-        self.delay = WRITE_PAD
-        if slow:
-            self.delay += WRITE_PAD_SLOWDOWN
+        self.delay = GetDelay(slow)
         self.delimiter = None
         # Stash away a copy in case we need to resplit
         text = logfp.read()
@@ -674,7 +679,7 @@ class TestSession:
                 chosen = self.choose()
                 if isinstance(chosen, FakeGPS):
                     if chosen.exhausted and (time.time() - chosen.exhausted > 
TEST_TIMEOUT) and chosen.byname in self.fakegpslist:
-                        sys.stderr.write("Test timed out: increase WRITE_PAD = 
%s\n" % WRITE_PAD)
+                        sys.stderr.write("Test timed out: increase WRITE_PAD = 
%s\n" % GetDelay(self.slow))
                         raise SystemExit, 1
                     elif not chosen.go_predicate(chosen.index, chosen):
                         if chosen.exhausted == 0:
diff --git a/gpsfake b/gpsfake
index 298a885..6c33396 100755
--- a/gpsfake
+++ b/gpsfake
@@ -152,7 +152,7 @@ if __name__ == '__main__':
         elif switch == '-t':
             tcp = True
         elif switch == '-T':
-            sys.stdout.write("sys %s platform %s: WRITE_PAD = %.5f\n" % 
(sys.platform, platform.platform(), gpsfake.WRITE_PAD))
+            sys.stdout.write("sys %s platform %s: WRITE_PAD = %.5f\n" % 
(sys.platform, platform.platform(), gpsfake.GetDelay(slow)))
             raise SystemExit, 0
         elif switch == '-u':
             udp = True
-- 
2.7.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]