コード例 #1
0
    def test_process_result_queue(self):
        handler = DerivedIPythonHandler()

        queue = CalculationQueue()
        queue.queue = MockQueue()

        queue.put("TestItem", "TestValue")

        calculation = handler.process(queue, some_variable=42, other_variable=21)

        self.assertEqual(len(calculation.process_list), 1)

        added_calculation = calculation.process_list[0]

        self.assertEqual(added_calculation.log_file_name, handler.log_files[0][1])
        self.assertEqual(added_calculation.result_queue, queue)
        self.assertEqual(added_calculation.result_queue.get_keys(), ["TestItem"])
        self.assertEqual(added_calculation.result_queue.get("TestItem"), "TestValue")
        self.assertEqual(added_calculation.parameters, None)
        self.assertEqual(added_calculation.some_variable, 42)
        self.assertEqual(added_calculation.other_variable, 21)

        self.assertEqual(calculation.get_keys(), ["TestItem"])
        self.assertEqual(calculation.get("TestItem"), "TestValue")
        self.assertEqual(calculation.get_parameters(), None)
コード例 #2
0
    def test_process_result_queue(self):
        handler = DerivedIPythonHandler()

        queue = CalculationQueue()
        queue.queue = MockQueue()

        queue.put("TestItem", "TestValue")

        calculation = handler.process(queue,
                                      some_variable=42,
                                      other_variable=21)

        self.assertEqual(len(calculation.process_list), 1)

        added_calculation = calculation.process_list[0]

        self.assertEqual(added_calculation.log_file_name,
                         handler.log_files[0][1])
        self.assertEqual(added_calculation.result_queue, queue)
        self.assertEqual(added_calculation.result_queue.get_keys(),
                         ["TestItem"])
        self.assertEqual(added_calculation.result_queue.get("TestItem"),
                         "TestValue")
        self.assertEqual(added_calculation.parameters, None)
        self.assertEqual(added_calculation.some_variable, 42)
        self.assertEqual(added_calculation.other_variable, 21)

        self.assertEqual(calculation.get_keys(), ["TestItem"])
        self.assertEqual(calculation.get("TestItem"), "TestValue")
        self.assertEqual(calculation.get_parameters(), None)
コード例 #3
0
    def create_calculations(self):
        process1 = CalculationProcess(CalculationQueue(), None, None)
        process2 = CalculationProcess(CalculationQueue(), None, None)
        process3 = CalculationProcess(CalculationQueue(), None, None)

        calculations = Calculation([process1, process2, process3])

        return calculations, process2
コード例 #4
0
    def setUp(self):
        queue = CalculationQueue()

        self.tmp_file_name = NamedTemporaryFile(delete=False).name

        self.process = LoggingCalculationProcess(result_queue=queue, log_file_name=self.tmp_file_name,
                                                 parameters=None)

        self.process.start()
        self.process.join()
コード例 #5
0
 def setUp(self):
     self.calculation_queue = CalculationQueue()
     self.calculation_queue.queue = MockQueue()
コード例 #6
0
class TestCalculationQueue(TestCase):

    def setUp(self):
        self.calculation_queue = CalculationQueue()
        self.calculation_queue.queue = MockQueue()

    def test_put(self):
        a = A()

        self.calculation_queue.put("TestItem", "TestContent")
        self.calculation_queue.put("TestItem2", 2.34)
        self.calculation_queue.put("TestItem3", a)

        items = self.calculation_queue.queue.internal_storage

        self.assertEqual(len(items), 3)
        self.assertEqual(items[0], CalculationQueueItem("TestItem", "TestContent"))
        self.assertEqual(items[1], CalculationQueueItem("TestItem2", 2.34))
        self.assertEqual(items[2], CalculationQueueItem("TestItem3", a))

    def test_fill_results_no_dubs(self):
        a = A()

        self.calculation_queue.put("TestItem", "TestContent")
        self.calculation_queue.put("TestItem2", 2.34)
        self.calculation_queue.put("TestItem3", a)

        self.calculation_queue.fill_results()

        self.assertEqual(self.calculation_queue.get("TestItem"), "TestContent")
        self.assertEqual(self.calculation_queue.get("TestItem2"), 2.34)
        self.assertEqual(self.calculation_queue.get("TestItem3"), a)

        self.assertIn("TestItem", self.calculation_queue.get_keys())
        self.assertIn("TestItem2", self.calculation_queue.get_keys())
        self.assertIn("TestItem3", self.calculation_queue.get_keys())

    def test_fill_results_dubs(self):
        self.calculation_queue.put("TestItem", "TestContent")
        self.calculation_queue.put("TestItem", 2.34)
        self.calculation_queue.put("TestItem2", "OtherContent")

        self.calculation_queue.fill_results()

        self.assertEqual(self.calculation_queue.get("TestItem"), 2.34)
        self.assertEqual(self.calculation_queue.get("TestItem2"), "OtherContent")

        self.assertIn("TestItem", self.calculation_queue.get_keys())
        self.assertIn("TestItem2", self.calculation_queue.get_keys())
コード例 #7
0
 def setUp(self):
     self.calculation_queue = CalculationQueue()
     self.calculation_queue.queue = MockQueue()
コード例 #8
0
class TestCalculationQueue(TestCase):
    def setUp(self):
        self.calculation_queue = CalculationQueue()
        self.calculation_queue.queue = MockQueue()

    def test_put(self):
        a = A()

        self.calculation_queue.put("TestItem", "TestContent")
        self.calculation_queue.put("TestItem2", 2.34)
        self.calculation_queue.put("TestItem3", a)

        items = self.calculation_queue.queue.internal_storage

        self.assertEqual(len(items), 3)
        self.assertEqual(items[0],
                         CalculationQueueItem("TestItem", "TestContent"))
        self.assertEqual(items[1], CalculationQueueItem("TestItem2", 2.34))
        self.assertEqual(items[2], CalculationQueueItem("TestItem3", a))

    def test_fill_results_no_dubs(self):
        a = A()

        self.calculation_queue.put("TestItem", "TestContent")
        self.calculation_queue.put("TestItem2", 2.34)
        self.calculation_queue.put("TestItem3", a)

        self.calculation_queue.fill_results()

        self.assertEqual(self.calculation_queue.get("TestItem"), "TestContent")
        self.assertEqual(self.calculation_queue.get("TestItem2"), 2.34)
        self.assertEqual(self.calculation_queue.get("TestItem3"), a)

        self.assertIn("TestItem", self.calculation_queue.get_keys())
        self.assertIn("TestItem2", self.calculation_queue.get_keys())
        self.assertIn("TestItem3", self.calculation_queue.get_keys())

    def test_fill_results_dubs(self):
        self.calculation_queue.put("TestItem", "TestContent")
        self.calculation_queue.put("TestItem", 2.34)
        self.calculation_queue.put("TestItem2", "OtherContent")

        self.calculation_queue.fill_results()

        self.assertEqual(self.calculation_queue.get("TestItem"), 2.34)
        self.assertEqual(self.calculation_queue.get("TestItem2"),
                         "OtherContent")

        self.assertIn("TestItem", self.calculation_queue.get_keys())
        self.assertIn("TestItem2", self.calculation_queue.get_keys())
コード例 #9
0
    def test_default_parameters(self):
        queue = CalculationQueue()
        process = DerivedCalculationProcess(result_queue=queue, log_file_name=None, parameters=None)

        self.assertFalse(process.is_alive())
        self.assertTrue(process.is_valid)
コード例 #10
0
 def get_terminated_process(self):
     queue = CalculationQueue()
     process = DerivedCalculationProcess(result_queue=queue, log_file_name=None, parameters=None)
     process.start()
     process.join()
     return process
コード例 #11
0
 def setUp(self):
     queue = CalculationQueue()
     self.process = OngoingCalculationProcess(result_queue=queue, log_file_name=None, parameters=None)