From 69cb31d09e3c20d0e187bf08210bd054206f8d7b Mon Sep 17 00:00:00 2001 From: John Doe Date: Thu, 16 Dec 2021 15:05:17 +0800 Subject: [PATCH] Redesign mocks, fake paths instead of fake class --- src/tests/mock/bitmessagemock.py | 16 ++++++++-------- src/tests/mock/pybitmessage/__init__.py | 0 src/tests/mock/pybitmessage/bitmessagekivy | 1 + .../{ => pybitmessage}/class_addressGenerator.py | 2 +- .../{ => pybitmessage}/class_objectProcessor.py | 2 +- .../{ => pybitmessage}/class_singleWorker.py | 6 +++--- src/tests/mock/{ => pybitmessage}/inventory.py | 2 +- .../{ => pybitmessage}/network/connectionpool.py | 0 .../mock/{ => pybitmessage}/network/stats.py | 0 src/tests/mock/pybitmessage/state.py | 0 10 files changed, 15 insertions(+), 14 deletions(-) create mode 100644 src/tests/mock/pybitmessage/__init__.py create mode 120000 src/tests/mock/pybitmessage/bitmessagekivy rename src/tests/mock/{ => pybitmessage}/class_addressGenerator.py (98%) rename src/tests/mock/{ => pybitmessage}/class_objectProcessor.py (97%) rename src/tests/mock/{ => pybitmessage}/class_singleWorker.py (85%) rename src/tests/mock/{ => pybitmessage}/inventory.py (94%) rename src/tests/mock/{ => pybitmessage}/network/connectionpool.py (100%) rename src/tests/mock/{ => pybitmessage}/network/stats.py (100%) create mode 100644 src/tests/mock/pybitmessage/state.py diff --git a/src/tests/mock/bitmessagemock.py b/src/tests/mock/bitmessagemock.py index 47069d0e..e309dc17 100644 --- a/src/tests/mock/bitmessagemock.py +++ b/src/tests/mock/bitmessagemock.py @@ -1,7 +1,7 @@ -from class_addressGenerator import FakeAddressGenerator -from class_singleWorker import MockSingleWorker -from class_objectProcessor import MockObjectProcessor -from inventory import MockInventory +from pybitmessage.class_addressGenerator import addressGenerator +from pybitmessage.class_singleWorker import singleWorker +from pybitmessage.class_objectProcessor import objectProcessor +from pybitmessage.inventory import Inventory class MockMain(): @@ -15,26 +15,26 @@ class MockMain(): daemon = config.safeGetBoolean('bitmessagesettings', 'daemon') # Start the address generation thread - addressGeneratorThread = FakeAddressGenerator() + addressGeneratorThread = addressGenerator() # close the main program even if there are threads left addressGeneratorThread.daemon = True addressGeneratorThread.start() # Start the thread that calculates POWs - singleWorkerThread = MockSingleWorker() + singleWorkerThread = singleWorker() # close the main program even if there are threads left singleWorkerThread.daemon = True singleWorkerThread.start() # Start the thread that calculates POWs - objectProcessorThread = MockObjectProcessor() + objectProcessorThread = objectProcessor() # DON'T close the main program even the thread remains. # This thread checks the shutdown variable after processing # each object. objectProcessorThread.daemon = False objectProcessorThread.start() - MockInventory() # init + Inventory() # init def main(): diff --git a/src/tests/mock/pybitmessage/__init__.py b/src/tests/mock/pybitmessage/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/tests/mock/pybitmessage/bitmessagekivy b/src/tests/mock/pybitmessage/bitmessagekivy new file mode 120000 index 00000000..ef6c5709 --- /dev/null +++ b/src/tests/mock/pybitmessage/bitmessagekivy @@ -0,0 +1 @@ +../../../bitmessagekivy \ No newline at end of file diff --git a/src/tests/mock/class_addressGenerator.py b/src/tests/mock/pybitmessage/class_addressGenerator.py similarity index 98% rename from src/tests/mock/class_addressGenerator.py rename to src/tests/mock/pybitmessage/class_addressGenerator.py index fbb34710..0aaed140 100644 --- a/src/tests/mock/class_addressGenerator.py +++ b/src/tests/mock/pybitmessage/class_addressGenerator.py @@ -60,7 +60,7 @@ class StoppableThread(threading.Thread): self.stop.set() -class FakeAddressGenerator(StoppableThread): +class addressGenerator(StoppableThread): """A thread for creating fake addresses""" name = "addressGenerator" address_list = list(fake_addresses.keys()) diff --git a/src/tests/mock/class_objectProcessor.py b/src/tests/mock/pybitmessage/class_objectProcessor.py similarity index 97% rename from src/tests/mock/class_objectProcessor.py rename to src/tests/mock/pybitmessage/class_objectProcessor.py index c418abc6..09120fc6 100644 --- a/src/tests/mock/class_objectProcessor.py +++ b/src/tests/mock/pybitmessage/class_objectProcessor.py @@ -15,7 +15,7 @@ from network import bmproto logger = logging.getLogger('default') -class MockObjectProcessor(threading.Thread): +class objectProcessor(threading.Thread): """ The objectProcessor thread, of which there is only one, receives network objects (msg, broadcast, pubkey, getpubkey) from the receiveDataThreads. diff --git a/src/tests/mock/class_singleWorker.py b/src/tests/mock/pybitmessage/class_singleWorker.py similarity index 85% rename from src/tests/mock/class_singleWorker.py rename to src/tests/mock/pybitmessage/class_singleWorker.py index 92ffffbd..49800c68 100644 --- a/src/tests/mock/class_singleWorker.py +++ b/src/tests/mock/pybitmessage/class_singleWorker.py @@ -12,11 +12,11 @@ from network import StoppableThread from six.moves import queue -class MockSingleWorker(StoppableThread): +class singleWorker(StoppableThread): """Thread for performing PoW""" def __init__(self): - super(MockSingleWorker, self).__init__(name="singleWorker") + super(singleWorker, self).__init__(name="singleWorker") proofofwork.init() self.busy = None @@ -27,7 +27,7 @@ class MockSingleWorker(StoppableThread): queues.workerQueue.put(("stopThread", "data")) except queue.Full: self.logger.error('workerQueue is Full') - super(MockSingleWorker, self).stopThread() + super(singleWorker, self).stopThread() def run(self): diff --git a/src/tests/mock/inventory.py b/src/tests/mock/pybitmessage/inventory.py similarity index 94% rename from src/tests/mock/inventory.py rename to src/tests/mock/pybitmessage/inventory.py index 4148156f..62468e86 100644 --- a/src/tests/mock/inventory.py +++ b/src/tests/mock/pybitmessage/inventory.py @@ -6,7 +6,7 @@ from singleton import Singleton # pylint: disable=old-style-class,too-few-public-methods @Singleton -class MockInventory(): +class Inventory(): """ Inventory singleton class which uses storage backends to manage the inventory. diff --git a/src/tests/mock/network/connectionpool.py b/src/tests/mock/pybitmessage/network/connectionpool.py similarity index 100% rename from src/tests/mock/network/connectionpool.py rename to src/tests/mock/pybitmessage/network/connectionpool.py diff --git a/src/tests/mock/network/stats.py b/src/tests/mock/pybitmessage/network/stats.py similarity index 100% rename from src/tests/mock/network/stats.py rename to src/tests/mock/pybitmessage/network/stats.py diff --git a/src/tests/mock/pybitmessage/state.py b/src/tests/mock/pybitmessage/state.py new file mode 100644 index 00000000..e69de29b