[Pkg-privacy-commits] [txtorcon] 61/96: cover some partially-covered if statements

Jérémy Bobbio lunar at moszumanska.debian.org
Sun Sep 6 18:33:40 UTC 2015


This is an automated email from the git hooks/post-receive script.

lunar pushed a commit to branch master
in repository txtorcon.

commit e41f9486db1a088ee7b79f914d56d6c372d914e6
Author: meejah <meejah at meejah.ca>
Date:   Fri Feb 6 02:01:03 2015 -0700

    cover some partially-covered if statements
---
 test/test_addrmap.py   |  7 +++++++
 test/test_circuit.py   | 11 ++++++++++-
 test/test_endpoints.py |  1 +
 test/test_fsm.py       |  7 +++++++
 test/test_router.py    |  8 ++++----
 test/test_stream.py    |  2 ++
 txtorcon/addrmap.py    |  2 +-
 7 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/test/test_addrmap.py b/test/test_addrmap.py
index af3ab50..1d50bf9 100644
--- a/test/test_addrmap.py
+++ b/test/test_addrmap.py
@@ -171,6 +171,13 @@ class AddrMapTests(unittest.TestCase):
     def addrmap_added(self, addr):
         self.addrmap.append(addr)
 
+    def test_double_add_listener(self):
+        am = AddrMap()
+        am.add_listener(self)
+        am.add_listener(self)
+
+        self.assertEqual(1, len(am.listeners))
+
     def test_listeners(self):
         self.expires = []
         self.addrmap = []
diff --git a/test/test_circuit.py b/test/test_circuit.py
index fc8844b..d62d54b 100644
--- a/test/test_circuit.py
+++ b/test/test_circuit.py
@@ -4,7 +4,11 @@ from twisted.trial import unittest
 from twisted.internet import defer
 from zope.interface import implements
 
-from txtorcon import Circuit, Stream, TorControlProtocol, TorState
+from txtorcon import Circuit
+from txtorcon import Stream
+from txtorcon import TorControlProtocol
+from txtorcon import TorState
+from txtorcon import Router
 from txtorcon.interface import IRouterContainer
 from txtorcon.interface import ICircuitListener
 from txtorcon.interface import ICircuitContainer
@@ -124,6 +128,7 @@ class CircuitTests(unittest.TestCase):
 
         circuit = Circuit(tor)
         circuit.listen(tor)
+        circuit.listen(tor)
         circuit.update('1 LAUNCHED PURPOSE=GENERAL'.split())
         circuit.unlisten(tor)
         circuit.update('1 EXTENDED $E11D2B2269CC25E67CA6C9FB5843497539A74FD0=eris PURPOSE=GENERAL'.split())
@@ -131,6 +136,7 @@ class CircuitTests(unittest.TestCase):
         self.assertTrue(1 in tor.circuits)
         self.assertEqual(len(tor.extend), 0)
         self.assertEqual(1, len(circuit.path))
+        self.assertEqual(0, len(circuit.listeners))
 
     def test_path_update(self):
         cp = TorControlProtocol()
@@ -247,6 +253,9 @@ class CircuitTests(unittest.TestCase):
         circuit = Circuit(tor)
         circuit.id = 1
         str(circuit)
+        router = Router(tor)
+        circuit.path.append(router)
+        str(circuit)
 
     def test_failed_reason(self):
         tor = FakeTorController()
diff --git a/test/test_endpoints.py b/test/test_endpoints.py
index dbc032a..f9c58b5 100644
--- a/test/test_endpoints.py
+++ b/test/test_endpoints.py
@@ -45,6 +45,7 @@ class EndpointTests(unittest.TestCase):
         endpoints._global_tor_lock = defer.DeferredLock()
         self.reactor = FakeReactorTcp(self)
         self.protocol = FakeControlProtocol([])
+        self.protocol.event_happened('INFO', 'something craaaaaaazy')
         self.protocol.event_happened(
             'INFO',
             'connection_dir_client_reached_eof(): Uploaded rendezvous '
diff --git a/test/test_fsm.py b/test/test_fsm.py
index e6d5db9..027f993 100644
--- a/test/test_fsm.py
+++ b/test/test_fsm.py
@@ -45,6 +45,13 @@ class FsmTests(unittest.TestCase):
         self.assertWarns(RuntimeWarning, "No next state",
                          txtorcon.spaghetti.__file__, fsm.process, "")
 
+    def test_two_states(self):
+        fsm = FSM([])
+        idle = State("I")
+        notidle = State("N")
+        fsm.add_state(idle)
+        fsm.add_state(notidle)
+
     def test_no_matcher(self):
         idle = State("I")
         other = State("O")
diff --git a/test/test_router.py b/test/test_router.py
index 743f707..e140c4d 100644
--- a/test/test_router.py
+++ b/test/test_router.py
@@ -43,10 +43,10 @@ class RouterTests(unittest.TestCase):
             router.id_hex,
             "$00786E43CCC5409753F25E36031C5CEA6EA43702"
         )
-        self.assertTrue(
-            isinstance(router.modified,
-                       datetime)
-        )
+
+        # we assert this twice to cover the cached + uncached cases
+        self.assertTrue(isinstance(router.modified, datetime))
+        self.assertTrue(isinstance(router.modified, datetime))
         self.assertEqual(router.policy, '')
 
     def test_unique_name(self):
diff --git a/test/test_stream.py b/test/test_stream.py
index ee8ddc5..5ab1ac9 100644
--- a/test/test_stream.py
+++ b/test/test_stream.py
@@ -212,6 +212,8 @@ class StreamTests(unittest.TestCase):
 
         stream = Stream(self)
         stream.listen(listener)
+        stream.listen(listener)
+        self.assertEqual(len(stream.listeners), 1)
         stream.unlisten(listener)
         self.assertEqual(len(stream.listeners), 0)
 
diff --git a/txtorcon/addrmap.py b/txtorcon/addrmap.py
index ec7c61a..930a5d8 100644
--- a/txtorcon/addrmap.py
+++ b/txtorcon/addrmap.py
@@ -42,7 +42,7 @@ class Addr(object):
         if gmtexpires is None:
             if len(args) == 3:
                 gmtexpires = expires
-            elif len(args) > 3:
+            else:
                 if args[2] == 'NEVER':
                     gmtexpires = args[2]
                 else:

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/txtorcon.git



More information about the Pkg-privacy-commits mailing list