def test_parameters_setter_valid_whitespace(self): """Test parameters setter when valid parameters are provided with extraneous whitespace.""" unit = GcodeParser() unit.parse("G1") self.assertEqual(unit.commandString, "G1", "The commandString should be 'G1'.") unit.parameters = " X 10 Y3.2 Foo " self.assertEqual( unit.parameters, "X 10 Y3.2 Foo", "The parameters should be the expected value." ) self.assertEqual( unit.commandString, "G1 X 10 Y3.2 Foo", "The commandString should be the expected value." ) self.assertEqual( unit.parameterDict, OrderedDict([ ("X", 10), ("Y", 3.2), ("F", None), ("O", None), ("", "Foo") ]), "The parameterDict should be the expected value." )
def test_parameters_setter_valid_escapes(self): """Test the parameters setter when valid parameters with escaped chars are provided.""" unit = GcodeParser() unit.parse("G1") self.assertEqual(unit.commandString, "G1", "The commandString should be 'G1'.") unit.parameters = r"X10 \\ \;Not a comment" self.assertEqual( unit.parameters, r"X10 \\ \;Not a comment", "The parameters should be the expected value." ) self.assertEqual( unit.commandString, r"G1 X10 \\ \;Not a comment", "The commandString should be the expected value." ) self.assertEqual( unit.parameterDict, OrderedDict([ ("X", 10), ("N", None), ("O", None), ("T", None), ("A", None), ("C", None), ("M", None), ("E", None), ("", r"\\ \;Not a comment") ]), "The parameterDict should be the expected value." )
def test_parameters_setter_invalid_comment(self): """Test parameters setter when parameters provided include a comment-like value.""" unit = GcodeParser() unit.parse("G1") self.assertEqual(unit.commandString, "G1", "The commandString should be 'G1'.") with self.assertRaises(ValueError): unit.parameters = "X10 Y3.2 Foo ;Invalid"