コード例 #1
0
    def test_parameter_variable_init_basic(self):
        """
        Smallest possible initialization
        """

        par = parameter_variable("test")
        self.assertEqual(par.name, "test")
コード例 #2
0
    def test_parameter_variable_write_complex_float(self, mock_f):
        """
        Testing that write to file is correct. Here a line is in a
        instrument parameter section. The write file operation is
        mocked and check using a patch. Here a parameter with a value
        is used. (float value)
        """

        par = parameter_variable("double",
                                 "test",
                                 value=5.4,
                                 comment="test comment")

        with mock_f('test.txt', 'w') as m_fo:
            par.write_parameter(m_fo, ")")

        expected_writes = [
            unittest.mock.call("double test"),
            unittest.mock.call(" = 5.4"),
            unittest.mock.call(")"),
            unittest.mock.call("// test comment"),
            unittest.mock.call("\n")
        ]

        mock_f.assert_called_with('test.txt', 'w')
        handle = mock_f()
        handle.write.assert_has_calls(expected_writes, any_order=False)
コード例 #3
0
    def test_parameter_variable_init_basic_type(self):
        """
        Initialization with a type
        """

        par = parameter_variable("double", "test")

        self.assertEqual(par.name, "test")
        self.assertEqual(par.type, "double ")  # space for easier writing
コード例 #4
0
    def test_parameter_variable_init_basic_type_value(self):
        """
        Initialization with type and value
        """

        par = parameter_variable("double", "test", value=518)

        self.assertEqual(par.name, "test")
        self.assertEqual(par.type, "double ")  # space for easier writing
        self.assertEqual(par.value, 518)
コード例 #5
0
    def test_parameter_variable_init_basic_value_comment(self):
        """
        Initialization with value and comment
        """

        par = parameter_variable("test", value=518, comment="test comment /")

        self.assertEqual(par.name, "test")
        self.assertEqual(par.type, "")
        self.assertEqual(par.value, 518)
        self.assertEqual(par.comment, "// test comment /")
コード例 #6
0
    def test_parameter_variable_init_basic_type_value_comment(self):
        """
        Initialization with type, value and comment
        """

        par = parameter_variable("double",
                                 "test",
                                 value=518,
                                 comment="test comment /")

        self.assertEqual(par.name, "test")
        self.assertEqual(par.type, "double ")  # space for easier writing
        self.assertEqual(par.value, 518)
        self.assertEqual(par.comment, "// test comment /")
コード例 #7
0
    def test_parameter_variable_write_basic(self, mock_f):
        """
        Testing that write to file is correct. Here a line is in a
        instrument parameter section. The write file operation is
        mocked and check using a patch. Here a simple parameter is
        used.
        """

        par = parameter_variable("double", "test")
        with mock_f('test.txt', 'w') as m_fo:
            par.write_parameter(m_fo, "")

        expected_writes = [
            unittest.mock.call("double test"),
            unittest.mock.call(""),
            unittest.mock.call(""),
            unittest.mock.call("\n")
        ]

        mock_f.assert_called_with('test.txt', 'w')
        handle = mock_f()
        handle.write.assert_has_calls(expected_writes, any_order=False)