[tor-commits] [bridgedb/master] Add a unittest runner to scripts/bridgedb.

isis at torproject.org isis at torproject.org
Sun Jan 12 06:06:30 UTC 2014


commit c9dc17e85b5f19b791b1a509fe65a1bb9e319b47
Author: Isis Lovecruft <isis at torproject.org>
Date:   Thu Oct 3 06:29:23 2013 +0000

    Add a unittest runner to scripts/bridgedb.
    
     * ADD commands 'test' and 'coverage' to scripts/bridgedb. To run
       twisted.trial based unittests, after BridgeDB has been installed, do:
           $ bridgedb test
       and to run the same tests under python-coverage, do:
           $ bridgedb coverage
    
     * ADD dependencies for unittests and coverage:
         - coverage
         - trialcoverage
         - sure
    
     * FIXES #9872
---
 requirements.txt |    3 +++
 scripts/bridgedb |   31 +++++++++++++++++++++++++++++--
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/requirements.txt b/requirements.txt
index 7dc41a4..5760060 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -4,11 +4,14 @@ Mako==0.8.1
 MarkupSafe==0.18
 Twisted==13.1.0
 argparse>=1.2.1
+coverage==3.6
 ipaddr>=2.1.10
 pyOpenSSL>=0.13
 pygeoip==0.2.7
 pygpgme==0.3
 recaptcha>=1.0rc1
 recaptcha-client>=1.0.6
+sure==1.2.2
+trialcoverage==0.3.12
 wsgiref>=0.1.2
 zope.interface>=4.0.5
diff --git a/scripts/bridgedb b/scripts/bridgedb
index 069cccd..8e8800b 100644
--- a/scripts/bridgedb
+++ b/scripts/bridgedb
@@ -1,4 +1,31 @@
 #!/usr/bin/env python
 
-import bridgedb.Main
-bridgedb.Main.run()
+import bridgedb
+import sys
+
+if len(sys.argv) == 1:
+    from bridgedb import Main
+    Main.run()
+else:
+    if sys.argv[1] in ('test', 'coverage'):
+        import os
+        from twisted.scripts import trial
+
+        if sys.argv[1] == 'coverage':
+            run_python_coverage = True
+
+        # Hack to set the PYTHONPATH:
+        sys.path[:] = map(os.path.abspath, sys.path)
+        sys.path.insert(0, os.path.abspath(os.getcwd()))
+
+        if run_python_coverage:
+            from coverage import coverage
+            cov = coverage()
+            cov.start()
+
+        sys.argv = ['trial', 'bridgedb']
+        trial.run()
+
+        if run_python_coverage:
+            cov.stop()
+            cov.html_report('.coverage-results')





More information about the tor-commits mailing list