[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [stem/master] Integration tests for stem.util.system functions
commit 1a30fbd6526b243468a6ca92f0223eb84ff9b21b
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date: Sun Oct 16 17:19:01 2011 -0700
Integration tests for stem.util.system functions
Very, very basic tests that the tor process is running and available.
---
run_tests.py | 13 +++++++++++--
test/integ/runner.py | 12 ++++++++++++
test/integ/system.py | 32 ++++++++++++++++++++++++++++++++
3 files changed, 55 insertions(+), 2 deletions(-)
diff --git a/run_tests.py b/run_tests.py
index dab1c4f..4f3eee7 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -10,6 +10,7 @@ import unittest
import test.unit.message
import test.unit.version
import test.integ.runner
+import test.integ.system
from stem.util import enum, term
@@ -17,11 +18,14 @@ OPT = "uit:h"
OPT_EXPANDED = ["unit", "integ", "targets=", "help"]
DIVIDER = "=" * 70
-# (name, class) tuples for all of our unit tests
+# (name, class) tuples for all of our unit and integration tests
UNIT_TESTS = (("stem.types.ControlMessage", test.unit.message.TestMessageFunctions),
("stem.types.Version", test.unit.version.TestVerionFunctions),
)
+INTEG_TESTS = (("stem.util.system", test.integ.system.TestSystemFunctions),
+ )
+
# Configurations that the intergration tests can be ran with. Attributs are
# tuples of the test runner and description.
TARGETS = enum.Enum(*[(v, v) for v in ("NONE", "NO_CONTROL", "NO_AUTH", "COOKIE", "PASSWORD", "SOCKET")])
@@ -113,8 +117,13 @@ if __name__ == '__main__':
integ_runner.run_setup()
integ_runner.start()
- # TODO: run tests
print term.format("Running tests...", term.Color.BLUE, term.Attr.BOLD)
+ for name, test_class in INTEG_TESTS:
+ print "%s\n%s\n%s\n" % (DIVIDER, name, DIVIDER)
+ suite = unittest.TestLoader().loadTestsFromTestCase(test_class)
+ unittest.TextTestRunner(verbosity=2).run(suite)
+ print
+
print
except OSError:
pass
diff --git a/test/integ/runner.py b/test/integ/runner.py
index 207c2e3..4805c20 100644
--- a/test/integ/runner.py
+++ b/test/integ/runner.py
@@ -127,4 +127,16 @@ class Runner:
self._tor_process.kill()
sys.stdout.write(term.format("done\n", term.Color.BLUE, term.Attr.BOLD))
print # extra newline
+
+ def get_pid(self):
+ """
+ Provides the process id of tor.
+
+ Returns:
+ int pid for the tor process, or None if it isn't running
+ """
+
+ if self._tor_process:
+ return self._tor_process.pid
+ else: return None
diff --git a/test/integ/system.py b/test/integ/system.py
new file mode 100644
index 0000000..6b38615
--- /dev/null
+++ b/test/integ/system.py
@@ -0,0 +1,32 @@
+"""
+Unit tests for the util.system functions in the context of a tor process.
+"""
+
+import unittest
+
+from stem.util import system
+
+class TestSystemFunctions(unittest.TestCase):
+ """
+ Tests the util.system functions against the tor process that we're running.
+ """
+
+ def test_is_available(self):
+ """
+ Checks the util.system.is_available function.
+ """
+
+ # since we're running tor it would be kinda sad if this didn't detect it
+ self.assertTrue(system.is_available("tor"))
+
+ # but it would be kinda weird if this did...
+ self.assertFalse(system.is_available("blarg_and_stuff"))
+
+ def test_is_running(self):
+ """
+ Checks the util.system.is_running function.
+ """
+
+ self.assertTrue(system.is_running("tor"))
+ self.assertFalse(system.is_running("blarg_and_stuff"))
+
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits