[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [arm/master] Clearning orphaned .pyc files when running tests



commit b927b7fd1b1dc80705261bf3b08ff5db6d12483a
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Mon Sep 16 15:02:24 2013 -0700

    Clearning orphaned .pyc files when running tests
    
    Orphaned bytecode has bitten me far too many times. Exterminating it with
    extreme prejudice.
---
 run_tests.py |   29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)

diff --git a/run_tests.py b/run_tests.py
index 2fb88de..1b7d544 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -7,8 +7,31 @@ Runs arm's unit tests. This is a curses application so we're pretty limited on
 the test coverage we can achieve, but exercising what we can.
 """
 
+import os
 import unittest
 
-tests = unittest.defaultTestLoader.discover('test', pattern='*.py')
-test_runner = unittest.TextTestRunner()
-test_runner.run(tests)
+
+def clean_orphaned_pyc():
+  for root, _, files in os.walk(os.path.dirname(__file__)):
+    for filename in files:
+      if filename.endswith('.pyc'):
+        pyc_path = os.path.join(root, filename)
+
+        if "__pycache__" in pyc_path:
+          continue
+
+        if not os.path.exists(pyc_path[:-1]):
+          print "Deleting orphaned pyc file: %s" % pyc_path
+          os.remove(pyc_path)
+
+
+def main():
+  clean_orphaned_pyc()
+
+  tests = unittest.defaultTestLoader.discover('test', pattern='*.py')
+  test_runner = unittest.TextTestRunner()
+  test_runner.run(tests)
+
+
+if __name__ == '__main__':
+  main()

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits