Exemple #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))
Exemple #2
0
    def test_get_undefined_variable(self):
        """
        Test that get None for an undefined variable.
        """
        interp = Interpreter()

        self.assertEqual(interp.get('x'), None)
Exemple #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))
Exemple #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))
Exemple #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')
Exemple #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))
Exemple #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))
Exemple #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))
Exemple #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))
Exemple #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)
Exemple #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))
Exemple #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')
Exemple #13
0
    def test_simple_set_script_integer(self):
        interp = Interpreter()

        interp.eval('set x 5')

        self.assertEqual(interp.get('x'), 5)
Exemple #14
0
    def test_float_set(self):
        interp = Interpreter()

        interp.eval('set x 12.34')

        self.assertEqual(interp.get('x'), 12.34)
Exemple #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)
Exemple #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')
Exemple #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))
Exemple #18
0
    def test_simple_set_script_string_single_quote(self):
        interp = Interpreter()

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

        self.assertEqual(interp.get('x'), '5')
Exemple #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')
Exemple #20
0
    def test_simple_set_script_string(self):
        interp = Interpreter()

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

        self.assertEqual(interp.get('x'), '5')
Exemple #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')
Exemple #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))