Пример #1
0
    def test_invalid_name(self):
        interp = Interpreter()

        with self.assertRaises(Exception) as context:
            interp.eval('set 3 5')

        self.assertTrue('Invalid variable name "3"' in str(context.exception))
Пример #2
0
    def test_get_undefined_variable(self):
        """
        Test that get None for an undefined variable.
        """
        interp = Interpreter()

        self.assertEqual(interp.get('x'), None)
Пример #3
0
    def test_missing_command(self):
        interp = Interpreter()

        with self.assertRaises(Exception) as context:
            interp.eval('qwerty')
        self.assertTrue(
            "Command \"qwerty\" not found." in str(context.exception))
Пример #4
0
    def test_normal(self):
        interp = Interpreter()

        with self.assertRaises(CommandError) as context:
            interp.eval('error "Hello world."')

        self.assertTrue('Hello world.' in str(context.exception))
Пример #5
0
    def test_string_starting_with_number_set(self):
        """ Not keen on this aspect of Tcl """
        interp = Interpreter()

        interp.eval('set x 123.4234excel')

        self.assertEqual(interp.get('x'), '123.4234excel')
Пример #6
0
    def test_simple_set_read_not_exist(self):
        interp = Interpreter()

        with self.assertRaises(VariableDoesNotExistError) as context:
            interp.eval('set x')

        self.assertTrue(
            'set: Variable "x" does not exist.' in str(context.exception))
Пример #7
0
    def test_invalid_arguments(self):
        interp = Interpreter()

        with self.assertRaises(IncorrectNumberOfArgumentsError) as context:
            interp.eval('error "Hello world." 34 45 56')
        print(str(context.exception))
        self.assertTrue('error: Expected 1 or 2 or 3 arguments but received 4.'
                        in str(context.exception))
Пример #8
0
    def test_malformed_script_2(self):
        interp = Interpreter()

        with self.assertRaises(Exception) as context:
            interp.eval('set x "cat"se')

        self.assertTrue(
            "Expecting space but got 'se'" in str(context.exception))
Пример #9
0
    def test_simple_set_script_incorrect_args_excess(self):
        interp = Interpreter()

        with self.assertRaises(IncorrectNumberOfArgumentsError) as context:
            interp.eval('set x 5 4')

        self.assertTrue("set: Expected 1 or 2 arguments but received 3" in str(
            context.exception))
Пример #10
0
    def test_set_and_get_variable(self):
        """
        Test that we can set and get a variable.
        """
        interp = Interpreter()

        interp.set('x', 5)

        self.assertEqual(interp.get('x'), 5)
Пример #11
0
    def test_cannot_set_variable_to_class(self):
        interp = Interpreter()

        with self.assertRaises(Exception) as context:
            interp.set('x', interp)

        self.assertTrue(
            "Cannot set a variable to type <class 'pytcl.interp.Interpreter'>"
            in str(context.exception))
Пример #12
0
    def test_simple_set_read(self):
        interp = Interpreter()

        interp.eval('set x "5"')
        result = interp.eval('set x')

        self.assertEqual(result.value, '5')
        self.assertEqual(interp.get('x'), '5')
Пример #13
0
    def test_simple_set_script_integer(self):
        interp = Interpreter()

        interp.eval('set x 5')

        self.assertEqual(interp.get('x'), 5)
Пример #14
0
    def test_float_set(self):
        interp = Interpreter()

        interp.eval('set x 12.34')

        self.assertEqual(interp.get('x'), 12.34)
Пример #15
0
    def test_float_with_exponent_set(self):
        interp = Interpreter()

        interp.eval('set x 12.34e-14')

        self.assertEqual(interp.get('x'), 1.234e-13)
Пример #16
0
    def test_string_set_single_quote(self):
        interp = Interpreter()

        interp.eval('set x \'This is a string\'')

        self.assertEqual(interp.get('x'), 'This is a string')
Пример #17
0
    def test_malformed_script_3(self):
        interp = Interpreter()

        with self.assertRaises(Exception) as context:
            interp.eval('2')
        self.assertTrue('invalid command name "2"' in str(context.exception))
Пример #18
0
    def test_simple_set_script_string_single_quote(self):
        interp = Interpreter()

        interp.eval('set x \'5\'')

        self.assertEqual(interp.get('x'), '5')
Пример #19
0
    def test_string_set(self):
        interp = Interpreter()

        interp.eval('set x "This is a string"')

        self.assertEqual(interp.get('x'), 'This is a string')
Пример #20
0
    def test_simple_set_script_string(self):
        interp = Interpreter()

        interp.eval('set x "5"')

        self.assertEqual(interp.get('x'), '5')
Пример #21
0
    def test_simple_set_string_script_2(self):
        interp = Interpreter()

        interp.set('x', "The quick brown fox")

        self.assertEqual(interp.get('x'), 'The quick brown fox')
Пример #22
0
    def test_malformed_script_1(self):
        interp = Interpreter()

        with self.assertRaises(Exception) as context:
            interp.eval('set x ]')
        self.assertTrue("Unexpected character ']'" in str(context.exception))