Beispiel #1
0
 def test_compound_user_query_handler(self):
     mock_handler = Mock()
     fixture = CommandInterpreter()
     mock_handler.query.return_value = "12.4"
     fixture.register_query_handler("VOLT:MEASURE", mock_handler)
     self.assertEqual(fixture.process_line("VOLT:MEASURE?"), "12.4\n")
     mock_handler.query.assert_called_with("VOLT:MEASURE")
Beispiel #2
0
 def _test_user_set_handler(self, string_value, expected_value):
     mock_handler = Mock()
     fixture = CommandInterpreter()
     mock_handler.set.return_value = "Ok"
     fixture.register_command_handler("SOMFUNC", mock_handler)
     self.assertEqual(fixture.process_line("SOMFUNC " + string_value),
                      "Ok\n")
     mock_handler.set.assert_called_with("SOMFUNC", expected_value)
Beispiel #3
0
 def test_user_set_handler_with_context(self):
     mock_handler = Mock()
     mock_call_context = "sdfsdf"
     fixture = CommandInterpreter()
     mock_handler.set.return_value = "Ok"
     fixture.register_command_handler("SOMFUNC", mock_handler)
     self.assertEqual(
         fixture.process_line("SOMFUNC 12.4", mock_call_context), "Ok\n")
     mock_handler.set.assert_called_with("SOMFUNC", 12.4, mock_call_context)
Beispiel #4
0
 def test_user_query_handler_with_call_context(self):
     mock_handler = Mock()
     mock_call_context = "Something"
     fixture = CommandInterpreter()
     mock_handler.query.return_value = "12.4"
     fixture.register_query_handler("VOLT", mock_handler)
     self.assertEqual(fixture.process_line("VOLT?", mock_call_context),
                      "12.4\n")
     mock_handler.query.assert_called_with("VOLT", mock_call_context)
Beispiel #5
0
 def test_multiple_queries_with_context(self):
     mock_handler1 = Mock()
     mock_handler2 = Mock()
     fixture = CommandInterpreter()
     mock_handler1.query.return_value = "10.0"
     mock_handler2.query.return_value = "12.0"
     fixture.register_query_handler("SOURCE:VOLTAGE", mock_handler1)
     fixture.register_query_handler("SOURCE:CURRENT", mock_handler2)
     self.assertEqual(fixture.process_line("SOURCE:VOLTAGE?; CURRENT?"),
                      "10.0\n12.0\n")
     mock_handler1.query.assert_called_with("SOURCE:VOLTAGE")
     mock_handler2.query.assert_called_with("SOURCE:CURRENT")
Beispiel #6
0
 def test_multiple_commands_with_context_override(self):
     mock_handler1 = Mock()
     mock_handler2 = Mock()
     fixture = CommandInterpreter()
     mock_handler1.set.return_value = "Ok"
     mock_handler2.set.return_value = "Ok"
     fixture.register_command_handler("SOURCE:VOLTAGE", mock_handler1)
     fixture.register_command_handler("OUTPUT:ENABLE", mock_handler2)
     self.assertEqual(
         fixture.process_line("SOURCE:VOLTAGE 12.4;:OUTPUT:ENABLE 1"),
         "Ok\nOk\n")
     mock_handler1.set.assert_called_with("SOURCE:VOLTAGE", 12.4)
     mock_handler2.set.assert_called_with("OUTPUT:ENABLE", 1)
Beispiel #7
0
 def test_multiple_commands_with_context(self):
     mock_handler1 = Mock()
     mock_handler2 = Mock()
     fixture = CommandInterpreter()
     mock_handler1.set.return_value = "Ok"
     mock_handler2.set.return_value = "Ok"
     fixture.register_command_handler("SOURCE:VOLTAGE", mock_handler1)
     fixture.register_command_handler("SOURCE:CURRENT", mock_handler2)
     self.assertEqual(
         fixture.process_line("SOURCE:VOLTAGE 12.4; CURRENT 10.0"),
         "Ok\nOk\n")
     mock_handler1.set.assert_called_with("SOURCE:VOLTAGE", 12.4)
     mock_handler2.set.assert_called_with("SOURCE:CURRENT", 10.0)
Beispiel #8
0
 def test_multiple_commands(self):
     mock_handler1 = Mock()
     mock_handler2 = Mock()
     fixture = CommandInterpreter()
     mock_handler1.set.return_value = "Ok"
     mock_handler2.set.return_value = "Ok"
     fixture.register_command_handler("SOMFUNC", mock_handler1)
     fixture.register_command_handler("SOMEOTHERFUNC", mock_handler2)
     self.assertEqual(
         fixture.process_line("SOMFUNC 12.4; SOMEOTHERFUNC 10.0"),
         "Ok\nOk\n")
     mock_handler1.set.assert_called_with("SOMFUNC", 12.4)
     mock_handler2.set.assert_called_with("SOMEOTHERFUNC", 10.0)
Beispiel #9
0
 def test_idn_defaults(self):
     fixture = CommandInterpreter("TestOrg", "TestModel")
     self.assertEqual(fixture.process_line("*IDN?"),
                      "TestOrg,TestModel,0,0\n")
Beispiel #10
0
 def test_empty(self):
     fixture = CommandInterpreter()
     self.assertEqual(fixture.process_line("\t\t\t  "), "\n")
Beispiel #11
0
 def test_syntax_error(self):
     fixture = CommandInterpreter()
     self.assertEqual(
         fixture.process_line("This is crap")[0:19], "No terminal matches")
Beispiel #12
0
 def test_no_query_handler(self):
     fixture = CommandInterpreter()
     self.assertEqual(fixture.process_line("something?"), "Invalid query\n")
Beispiel #13
0
 def test_idn(self):
     fixture = CommandInterpreter("TestOrg", "TestModel", "12.0", "1.0")
     self.assertEqual(fixture.process_line("*IDN?"),
                      "TestOrg,TestModel,12.0,1.0\n")