コード例 #1
0
    def test_ParameterVariable_write_complex_float(self, mock_f):
        """
        Testing that write to file is correct. Here a line is in an
        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 = ParameterVariable("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)
コード例 #2
0
    def test_get_parameter_default_int(self):
        """
        Get default value from integer value, should be rounded
        """

        par = ParameterVariable("int", "test", value=5.7)
        self.assertEqual(get_parameter_default(par), 5)
コード例 #3
0
    def test_ParameterVariable_init_basic(self):
        """
        Smallest possible initialization
        """

        par = ParameterVariable("test")
        self.assertEqual(par.name, "test")
コード例 #4
0
    def test_get_parameter_default_double(self):
        """
        Get the default for parameter that was double by default
        """

        par = ParameterVariable("test", value=5.7)
        self.assertEqual(get_parameter_default(par), 5.7)
コード例 #5
0
    def test_get_parameter_default_double_specified(self):
        """
        Get the default for specified double parameter
        """

        par = ParameterVariable("double", "test", value=5.5)
        self.assertEqual(get_parameter_default(par), 5.5)
コード例 #6
0
    def test_get_parameter_default_string(self):
        """
        Get the default for string parameter
        """

        par = ParameterVariable("string", "test", value="variable")
        self.assertEqual(get_parameter_default(par), "variable")
コード例 #7
0
    def test_parameter_has_default_true(self):
        """
        Check for parameter that has default, should be true
        """

        par = ParameterVariable("test", value=8)
        self.assertTrue(parameter_has_default(par))
コード例 #8
0
    def test_parameter_has_default_false(self):
        """
        Check for parameter that does not have default, should be false
        """

        par = ParameterVariable("test")
        self.assertFalse(parameter_has_default(par))
コード例 #9
0
    def test_ParameterVariable_init_basic_type(self):
        """
        Initialization with a type
        """

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

        self.assertEqual(par.name, "test")
        self.assertEqual(par.type, "double")
コード例 #10
0
    def test_ParameterVariable_init_basic_type_value(self):
        """
        Initialization with type and value
        """

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

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

        par = ParameterVariable("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 /")
コード例 #12
0
    def test_ParameterVariable_write_basic(self, mock_f):
        """
        Testing that write to file is correct. Here a line is in an
        instrument parameter section. The write file operation is
        mocked and check using a patch. Here a simple parameter is
        used.
        """

        par = ParameterVariable("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)