Пример #1
0
    def test_Component_write_to_file_simple(self, mock_f):
        """
        Testing that a Component can be written to file with the
        expected output. Here with simple input.
        """

        comp = Component("test_component", "Arm")

        comp._unfreeze()
        # Need to set up attribute parameters
        # Also need to categorize them as when created
        comp.parameter_names = []
        comp.parameter_defaults = {}
        comp.parameter_types = {}
        comp._freeze()

        with mock_f('test.txt', 'w') as m_fo:
            comp.write_component(m_fo)

        my_call = unittest.mock.call
        expected_writes = [
            my_call("COMPONENT test_component = Arm("),
            my_call(")\n"),
            my_call("AT (0,0,0)"),
            my_call(" ABSOLUTE\n")
        ]

        mock_f.assert_called_with('test.txt', 'w')
        handle = mock_f()
        handle.write.assert_has_calls(expected_writes, any_order=False)
Пример #2
0
    def test_Component_freeze(self):
        """
        Testing frozen Component cant have new attributes, and that
        _unfreeze / _freeze works correctly.
        """
        comp = Component("test_component", "Arm")

        with self.assertRaises(AttributeError):
            comp.new_parameter = 5

        self.assertEqual(comp.name, "test_component")
        self.assertEqual(comp.component_name, "Arm")

        comp._unfreeze()
        comp.new_parameter = 5

        self.assertEqual(comp.new_parameter, 5)

        comp._freeze()
        with self.assertRaises(AttributeError):
            comp.another_parameter = 5