[chirp_devel] [PATCH] Fix minor bugs in run_tests (#2343, #2347)
# HG changeset patch # User Zachary T Welch zach@mandolincreekfarm.com # Fake Node ID ce229849be37b442a3b1be0217b3e4994d469787
Fix minor bugs in run_tests (#2343, #2347)
This patch contains two fixes for the run_tests.
The first change resolves problems when running the script without a path component in its name (either as 'python run_tests' or with PATH="./tests:${PATH}"). Now, we do not try to change directory unless there is a path component.
The second problem was that the logs directory will not exist in a clean working copy of the repository. It was being created after the logger module was called. That is resolved by moving the directory creation step to occur before the initialization of the logger module options.
diff --git a/tests/run_tests b/tests/run_tests index 689fe92..bc54136 100755 --- a/tests/run_tests +++ b/tests/run_tests @@ -25,9 +25,11 @@ import time from optparse import OptionParser from serial import Serial
-# change to the tests directory -scriptdir = os.path.dirname(sys.argv[0]) -os.chdir(scriptdir) +if __name__ == "__main__": + # change to the tests directory + scriptdir = os.path.dirname(sys.argv[0]) + if scriptdir: + os.chdir(scriptdir)
sys.path.insert(0, "../")
@@ -40,7 +42,10 @@ class LoggerOpts(object): log_file = os.path.join('logs', 'debug.log') log_level = logging.DEBUG
-logger.handle_options(LoggerOpts()) +if __name__ == "__main__": + if not os.path.exists("logs"): + os.mkdir("logs") + logger.handle_options(LoggerOpts())
from chirp import CHIRP_VERSION from chirp.drivers import * @@ -1021,8 +1026,6 @@ class TestRunner: self._test_out = test_out if not os.path.exists("tmp"): os.mkdir("tmp") - if not os.path.exists("logs"): - os.mkdir("logs")
def _make_list(self): run_list = []
-# change to the tests directory -scriptdir = os.path.dirname(sys.argv[0]) -os.chdir(scriptdir) +if __name__ == "__main__":
- # change to the tests directory
- scriptdir = os.path.dirname(sys.argv[0])
- if scriptdir:
os.chdir(scriptdir)
Why protect this with the __main__ check? This is never imported from anywhere, so we're always in __main__ at this scope.
-logger.handle_options(LoggerOpts()) +if __name__ == "__main__":
- if not os.path.exists("logs"):
os.mkdir("logs")
- logger.handle_options(LoggerOpts())
Same.
That said, with that applied, I can run tests on windows properly.
--Dan
On 03/15/2015 12:43 PM, Dan Smith wrote:
-# change to the tests directory -scriptdir = os.path.dirname(sys.argv[0]) -os.chdir(scriptdir) +if __name__ == "__main__":
- # change to the tests directory
- scriptdir = os.path.dirname(sys.argv[0])
- if scriptdir:
os.chdir(scriptdir)
Why protect this with the __main__ check? This is never imported from anywhere, so we're always in __main__ at this scope.
-logger.handle_options(LoggerOpts()) +if __name__ == "__main__":
- if not os.path.exists("logs"):
os.mkdir("logs")
- logger.handle_options(LoggerOpts())
Same.
That said, with that applied, I can run tests on windows properly.
I believe that running a script via 'python <script>' causes it to first be imported and then run. At the very least, 'pydoc run_tests' will cause the module to be imported but it should not be run.
I don't think there's anything wrong with adding those checks, and there are definitely situations where it's right.
participants (3)
-
Dan Smith
-
Zach Welch
-
Zachary T Welch