[tor-commits] [compass/master] Added another testcase to the unit tests. Improved README
karsten at torproject.org
karsten at torproject.org
Wed Jan 16 15:09:56 UTC 2013
commit d8462b4e97b3ea6b0449208c6bb6bc56daf5fdc8
Author: Chris Wacek <cwacek at cs.georgetown.edu>
Date: Tue Jan 15 16:19:49 2013 -0500
Added another testcase to the unit tests. Improved README
---
testing/README | 35 ++++++++++++++++++++++++++++-------
testing/app_tests.py | 9 +++++++++
testing/testdata.json | 34 +++++++++++++++++++++++++++++++++-
3 files changed, 70 insertions(+), 8 deletions(-)
diff --git a/testing/README b/testing/README
index 9457b1e..7e9c50f 100644
--- a/testing/README
+++ b/testing/README
@@ -1,13 +1,34 @@
+Testing
+=======
-These are a set of scripts designed to makes sure that any
-changes I have made don't change the behavior of the original
-compass.py. test.sh will run a series of command line switches
-at compass.py, and save the output in a series of named test
+Unit Tests
+----------
+I've started writing unit tests when bugs are encountered.
+The tests are written using UnitTest, and can be run as follows:
+
+```python
+cd compass
+nosetests
+```
+
+Most of the tests are checking against JSON output. Where
+reasonably small I have inlined the expected result in the
+testcases, but in certain cases I've included them as files in
+the `expectations` directory.
+
+Regression Tests
+----------------
+
+These are a set of scripts designed to make sure that changes to
+the command line version of `compass.py` don't result in
+different output than before. They're not pretty, but they work.
+
+`test.sh` will run a series of command line switches
+at `compass.py`, and save the output in a series of named test
files.
-check.py will take two test names and compare the output
+`check.py` will take two test names and compare the output
from those tests to see if they match.
-
-Note: Sometimes a test will fail even though the output is correct
+*Note:* Sometimes a test will fail even though the output is correct
because the sorting works differently in my revised version and
elements with the same value don't always occur in the same order.
diff --git a/testing/app_tests.py b/testing/app_tests.py
index 6248241..28eff17 100644
--- a/testing/app_tests.py
+++ b/testing/app_tests.py
@@ -35,6 +35,15 @@ class TestCase(unittest.TestCase):
""")
self.assertItemsEqual(received,expected)
+ def test_select_AS1234567890(self):
+ received = json.loads(self.app.get("/result.json?ases=AS1234567890").data)
+ expected = json.loads(
+"""
+{"total": {"fp": "", "index": null, "as_no": "", "nick": "", "cc": "", "p_exit": 0.0, "adv_bw": 0.0, "guard": "", "link": true, "p_guard": 0.0, "p_middle": 0.0, "exit": "", "as_info": "", "cw": 0.0, "as_name": ""}, "results": [], "excluded": null}
+"""
+ )
+ self.assertItemsEqual(received,expected)
+
def test_select_AS_with_label(self):
received = json.loads(self.app.get("/result.json?ases=AS7922").data)
expected = json.loads(
diff --git a/testing/testdata.json b/testing/testdata.json
index 94f079e..d3a22ac 100644
--- a/testing/testdata.json
+++ b/testing/testdata.json
@@ -449,4 +449,36 @@
],
"contact":"r dot p dot j at wxs dot nl",
"platform":"Tor 0.2.2.39 (git-bec76476efb71549) on Windows 7 Service Pack 1 [workstation]"
-}]}
+},
+{"nickname":"winner",
+"fingerprint":"9DD3F90D641D835C4FCA7153148B156E6FD49CEE",
+"or_addresses":["46.4.106.18:443"],
+"dir_address":"46.4.106.18:9030",
+"running":true,
+"flags":["Fast","Guard","HSDir","Named","Running","Stable","V2Dir","Valid"],
+"country":"de",
+"latitude":51.000000,
+"longitude":9.000000,
+"country_name":"Germany",
+"as_number":"AS3",
+"as_name":"Hetzner Online AG RZ",
+"consensus_weight":8750,
+"host_name":"static.18.106.4.46.clients.your-server.de",
+"advertised_bandwidth_fraction":0.001122543,
+"consensus_weight_fraction":0.000915991,
+"guard_probability":0.002748011,
+"middle_probability":0.000000000,
+"exit_probability":0.000000000,
+"exit_policy_summary":{"reject":["1-65535"]},
+"last_restarted":"2012-10-26 22:15:33",
+"bandwidth_rate":4096000,
+"bandwidth_burst":9216000,
+"observed_bandwidth":5059825,
+"advertised_bandwidth":4096000,
+"exit_policy":[
+ "reject *:*"
+],
+"contact":"TlpCRm91bmRhdGlvbit0b3JAZ21haWwuY29t",
+"platform":"Tor 0.2.3.24-rc on Linux"
+}
+]}
More information about the tor-commits
mailing list