コード例 #1
0
ファイル: test_input.py プロジェクト: mwvgroup/Egon
class InputIterGet(TestCase):
    """Test iteration behavior of the ``iter_get`` method"""

    def setUp(self) -> None:
        """Create an input connector that is assigned to a parent node

        The input connector must be assigned to a parent node, otherwise
        ``iter_get`` raises an error.
        """

        self.input_connector = MockTarget().input

    def test_raises_stop_iteration_on_kill_signal(self) -> None:
        """Test the iterator exits once it reaches a KillSignal object"""

        self.input_connector._queue.put(KillSignal)
        with self.assertRaises(StopIteration):
            next(self.input_connector.iter_get())

    def test_raises_missing_connection_with_no_parent(self) -> None:
        """Test the iterator exits if input has no paren"""

        with self.assertRaises(MissingConnectionError):
            next(Input().iter_get())

    def test_returns_queue_value(self) -> None:
        """Test the ``get`` method retrieves data from the underlying queue"""

        test_val = 'test_val'
        self.input_connector._queue.put(test_val)
        time.sleep(1)  # Give queue time to update

        self.assertEqual(next(self.input_connector.iter_get()), test_val)
コード例 #2
0
ファイル: testFitLightCurves.py プロジェクト: LSSTDESC/SN-PWV
    def generic_setup(cls, vparams: List[str]) -> None:
        """Set up nodes for feeding/accumulating a mock fitting pipeline

        Args:
            vparams: Parameters to vary in the fit
        """

        cls.packet = create_mock_pipeline_packet(include_fit=False)

        # Create a mock pipeline for fitting the packet's light-curve
        source = MockSource([cls.packet])
        cls.node = FitLightCurves(SNModel('salt2-extended'),
                                  vparams=vparams,
                                  num_processes=0)
        cls.success_target = MockTarget()
        cls.failure_target = MockTarget()

        source.output.connect(cls.node.input)
        cls.node.success_output.connect(cls.success_target.input)
        cls.node.failure_output.connect(cls.failure_target.input)

        # Run the mock pipeline
        for mock_node in (source, cls.node, cls.success_target,
                          cls.failure_target):
            mock_node.execute()
            sleep(2)
コード例 #3
0
ファイル: test_input.py プロジェクト: mwvgroup/Egon
    def setUp(self) -> None:
        """Create an input connector that is assigned to a parent node

        The input connector must be assigned to a parent node, otherwise
        ``iter_get`` raises an error.
        """

        self.input_connector = MockTarget().input
コード例 #4
0
    def setUp(self) -> None:
        """Set up mock nodes for feeding/accumulating a ``SimulateLightCurves`` instance"""

        # Set up separate target node for each of the ``SimulateLightCurves`` output connectors
        self.source = MockSource()
        self.node = SimulateLightCurves(SNModel('salt2-extended'),
                                        num_processes=0)
        self.success_target = MockTarget()
        self.failure_target = MockTarget()

        self.source.output.connect(self.node.input)
        self.node.success_output.connect(self.success_target.input)
        self.node.failure_output.connect(self.failure_target.input)
コード例 #5
0
ファイル: test_pipeline.py プロジェクト: mwvgroup/Egon
    def __init__(self) -> None:
        self.source = MockSource([1, 2, 3])
        self.inline = MockNode()
        self.target = MockTarget()

        self.source.output.connect(self.inline.input)
        self.inline.output.connect(self.target.input)
        super(SimplePipeline, self).__init__()
コード例 #6
0
    def setUpClass(cls) -> None:
        """Use the ``LoadPlasticcCadence`` node to load data into a mock pipeline"""

        # Create a mock pipeline
        cadence = PLAsTICC('alt_sched', 11)
        load_action = LoadPlasticcCadence(cadence, num_processes=0)
        mock_target = MockTarget()

        # Execute the pipeline
        load_action.output.connect(mock_target.input)
        load_action.execute()
        mock_target.execute()

        # pipeline results
        cls.packet = mock_target.accumulated_data[0]

        # manually loaded results
        cls.snid, cls.params, cls.cadence = next(
            cadence.iter_cadence(iter_lim=1, verbose=False))
コード例 #7
0
    def runTest(self) -> None:
        # Create one node to output data and two to accept it
        test_data = [1, 2, 3]
        source = MockSource(test_data)
        target_a = MockTarget()
        target_b = MockTarget()

        # Connect two outputs to the same input
        source.output.connect(target_a.input)
        source.output.connect(target_b.input)

        source.execute()
        sleep(1)  # Give the queue a chance to update

        # Both inputs should have received the same data from the output
        target_a.execute()
        self.assertListEqual(test_data, target_a.accumulated_data)

        target_b.execute()
        self.assertListEqual(test_data, target_b.accumulated_data)
コード例 #8
0
ファイル: test_input.py プロジェクト: mwvgroup/Egon
    def test_kill_signal_on_finished_parent_node(self) -> None:
        """Test a kill signal is returned if the parent node is finished"""

        target = MockTarget()
        self.assertFalse(target.is_expecting_data())
        self.assertIs(target.input.get(timeout=15), KillSignal)