From a5d3c0bbe1dcfcfe18290cd840b49374d6bb6bc4 Mon Sep 17 00:00:00 2001 From: Job Evers-Meltzer Date: Wed, 19 Oct 2016 16:21:24 -0500 Subject: [PATCH] rename tests such that trial automatically runs them --- tests/dht/runalltests.py | 33 ------------- tests/dht/testContact.py | 47 ------------------ tests/unit/dht/__init__.py | 0 tests/unit/dht/test_contact.py | 49 +++++++++++++++++++ .../dht/test_datastore.py} | 0 .../dht/test_encoding.py} | 0 .../dht/test_kbucket.py} | 0 .../dht/test_messages.py} | 0 8 files changed, 49 insertions(+), 80 deletions(-) delete mode 100755 tests/dht/runalltests.py delete mode 100644 tests/dht/testContact.py create mode 100644 tests/unit/dht/__init__.py create mode 100644 tests/unit/dht/test_contact.py rename tests/{dht/testDatastore.py => unit/dht/test_datastore.py} (100%) rename tests/{dht/testEncoding.py => unit/dht/test_encoding.py} (100%) rename tests/{dht/testKBucket.py => unit/dht/test_kbucket.py} (100%) rename tests/{dht/testMessages.py => unit/dht/test_messages.py} (100%) diff --git a/tests/dht/runalltests.py b/tests/dht/runalltests.py deleted file mode 100755 index 74f2a1e3f..000000000 --- a/tests/dht/runalltests.py +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env python -# -# This library is free software, distributed under the terms of -# the GNU Lesser General Public License Version 3, or any later version. -# See the COPYING file included in this archive - -""" Wrapper script to run all included test scripts """ - -import os, sys -import unittest - -def runTests(): - testRunner = unittest.TextTestRunner() - testRunner.run(additional_tests()) - -def additional_tests(): - """ Used directly by setuptools to run unittests """ - sys.path.insert(0, os.path.dirname(__file__)) - suite = unittest.TestSuite() - tests = os.listdir(os.path.dirname(__file__)) - tests = [n[:-3] for n in tests if n.startswith('test') and n.endswith('.py')] - for test in tests: - m = __import__(test) - if hasattr(m, 'suite'): - suite.addTest(m.suite()) - sys.path.pop(0) - return suite - - -if __name__ == '__main__': - # Add parent folder to sys path so it's easier to use - sys.path.insert(0,os.path.abspath('..')) - runTests() diff --git a/tests/dht/testContact.py b/tests/dht/testContact.py deleted file mode 100644 index 6c475cf28..000000000 --- a/tests/dht/testContact.py +++ /dev/null @@ -1,47 +0,0 @@ -#!/usr/bin/env python -# -# This library is free software, distributed under the terms of -# the GNU Lesser General Public License Version 3, or any later version. -# See the COPYING file included in this archive - -import unittest - -import lbrynet.dht.contact - -class ContactOperatorsTest(unittest.TestCase): - """ Basic tests case for boolean operators on the Contact class """ - def setUp(self): - self.firstContact = lbrynet.dht.contact.Contact('firstContactID', '127.0.0.1', 1000, None, 1) - self.secondContact = lbrynet.dht.contact.Contact('2ndContactID', '192.168.0.1', 1000, None, 32) - self.secondContactCopy = lbrynet.dht.contact.Contact('2ndContactID', '192.168.0.1', 1000, None, 32) - self.firstContactDifferentValues = lbrynet.dht.contact.Contact('firstContactID', '192.168.1.20', 1000, None, 50) - - def testBoolean(self): - """ Test "equals" and "not equals" comparisons """ - self.failIfEqual(self.firstContact, self.secondContact, 'Contacts with different IDs should not be equal.') - self.failUnlessEqual(self.firstContact, self.firstContactDifferentValues, 'Contacts with same IDs should be equal, even if their other values differ.') - self.failUnlessEqual(self.secondContact, self.secondContactCopy, 'Different copies of the same Contact instance should be equal') - - def testStringComparisons(self): - """ Test comparisons of Contact objects with str types """ - self.failUnlessEqual('firstContactID', self.firstContact, 'The node ID string must be equal to the contact object') - self.failIfEqual('some random string', self.firstContact, "The tested string should not be equal to the contact object (not equal to it's ID)") - - def testIllogicalComparisons(self): - """ Test comparisons with non-Contact and non-str types """ - for item in (123, [1,2,3], {'key': 'value'}): - self.failIfEqual(self.firstContact, item, '"eq" operator: Contact object should not be equal to %s type' % type(item).__name__) - self.failUnless(self.firstContact != item, '"ne" operator: Contact object should not be equal to %s type' % type(item).__name__) - - def testCompactIP(self): - self.assertEqual(self.firstContact.compact_ip(), '\x7f\x00\x00\x01') - self.assertEqual(self.secondContact.compact_ip(), '\xc0\xa8\x00\x01') - -def suite(): - suite = unittest.TestSuite() - suite.addTest(unittest.makeSuite(ContactOperatorsTest)) - return suite - -if __name__ == '__main__': - # If this module is executed from the commandline, run all its tests - unittest.TextTestRunner().run(suite()) diff --git a/tests/unit/dht/__init__.py b/tests/unit/dht/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/unit/dht/test_contact.py b/tests/unit/dht/test_contact.py new file mode 100644 index 000000000..da361b364 --- /dev/null +++ b/tests/unit/dht/test_contact.py @@ -0,0 +1,49 @@ +import unittest + +from lbrynet.dht import contact + + +class ContactOperatorsTest(unittest.TestCase): + """ Basic tests case for boolean operators on the Contact class """ + def setUp(self): + self.firstContact = contact.Contact('firstContactID', '127.0.0.1', 1000, None, 1) + self.secondContact = contact.Contact('2ndContactID', '192.168.0.1', 1000, None, 32) + self.secondContactCopy = contact.Contact('2ndContactID', '192.168.0.1', 1000, None, 32) + self.firstContactDifferentValues = contact.Contact( + 'firstContactID', '192.168.1.20', 1000, None, 50) + + def testBoolean(self): + """ Test "equals" and "not equals" comparisons """ + self.failIfEqual( + self.firstContact, self.secondContact, + 'Contacts with different IDs should not be equal.') + self.failUnlessEqual( + self.firstContact, self.firstContactDifferentValues, + 'Contacts with same IDs should be equal, even if their other values differ.') + self.failUnlessEqual( + self.secondContact, self.secondContactCopy, + 'Different copies of the same Contact instance should be equal') + + def testStringComparisons(self): + """ Test comparisons of Contact objects with str types """ + self.failUnlessEqual( + 'firstContactID', self.firstContact, + 'The node ID string must be equal to the contact object') + self.failIfEqual( + 'some random string', self.firstContact, + "The tested string should not be equal to the contact object (not equal to it's ID)") + + def testIllogicalComparisons(self): + """ Test comparisons with non-Contact and non-str types """ + msg = '"{}" operator: Contact object should not be equal to {} type' + for item in (123, [1,2,3], {'key': 'value'}): + self.failIfEqual( + self.firstContact, item, + msg.format('eq', type(item).__name__)) + self.failUnless( + self.firstContact != item, + msg.format('ne', type(item).__name__)) + + def testCompactIP(self): + self.assertEqual(self.firstContact.compact_ip(), '\x7f\x00\x00\x01') + self.assertEqual(self.secondContact.compact_ip(), '\xc0\xa8\x00\x01') diff --git a/tests/dht/testDatastore.py b/tests/unit/dht/test_datastore.py similarity index 100% rename from tests/dht/testDatastore.py rename to tests/unit/dht/test_datastore.py diff --git a/tests/dht/testEncoding.py b/tests/unit/dht/test_encoding.py similarity index 100% rename from tests/dht/testEncoding.py rename to tests/unit/dht/test_encoding.py diff --git a/tests/dht/testKBucket.py b/tests/unit/dht/test_kbucket.py similarity index 100% rename from tests/dht/testKBucket.py rename to tests/unit/dht/test_kbucket.py diff --git a/tests/dht/testMessages.py b/tests/unit/dht/test_messages.py similarity index 100% rename from tests/dht/testMessages.py rename to tests/unit/dht/test_messages.py