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

[tor-commits] [bridgedb/master] Filter out <br /> tags in mechanize tests in test_https.py.



commit 8c6f0bdd023753540400533d40f8de84b6122caf
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date:   Wed Feb 18 20:53:30 2015 +0000

    Filter out <br /> tags in mechanize tests in test_https.py.
    
    These tests were intermittently failing (again) do the the
    ``split('<br></br>')`` call.  This was due to the template engine, Mako,
    sometimes deciding to use ``<br></br>`` and other times only ``<br />``.
    
    Additionally, BridgeDB (somewhat) dynamically determines the number of
    bridges to give out to a client based on the number of bridges in the
    pool, ergo with different HTTPS_SHARE:EMAIL_SHARE:RESERVED_SHARE
    proportions and a low number of descriptors (as is the case in
    BridgeDB's CI setup) the number of bridges in a response may
    occaisionally wobble between 1 and *_N_BRIDGES_PER_ANSWER (in increments
    of 1, i.e. it might give 1 or 2 bridges, or 3 or 4, but not 2 or 4).
    Usually, for the CI server case, it was usually 1 bridge because of the
    low number of mocked descriptors, but occaisionally it was 2.  This thus
    sometimes (when the number of bridges in the response was randomly 2)
    caused the ``split('<br></br>')`` call to sometimes (when Mako decides
    to randomly shorten ``<br></br>`` into ``<br />``) smash together the
    fingerprint of the first bridge line with the address or PT methodname
    of the second bridge line, which then of course caused the tests to fail
    (because the number of expected elements/words in the bridge lines has
    hardcoded test assertions for each type of bridge line).
    
    Hooray non-determinism.
---
 lib/bridgedb/test/test_https.py |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/bridgedb/test/test_https.py b/lib/bridgedb/test/test_https.py
index 86b1f84..fe9e4e3 100644
--- a/lib/bridgedb/test/test_https.py
+++ b/lib/bridgedb/test/test_https.py
@@ -132,10 +132,13 @@ class HTTPTests(unittest.TestCase):
         self.assertTrue(soup, "Could not find <div class='bridge-lines'>!")
 
         for portion in soup:
-            bridge_lines = portion.text.strip().split('<br></br>')
+            br_tags = portion.findChildren('br')
+            bridge_lines = set(portion.contents).difference(set(br_tags))
             for bridge_line in bridge_lines:
-                fields = bridge_line.split()
-                bridges.append(fields)
+                bridge_line = bridge_line.strip()
+                if bridge_line:
+                    fields = bridge_line.split()
+                    bridges.append(fields)
 
         self.assertTrue(len(bridges) > 0, "Found no bridge lines in %s" % soup)
 



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