Esempio n. 1
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))
Esempio n. 2
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))
Esempio n. 3
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')
Esempio n. 4
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))
Esempio n. 5
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))
Esempio n. 6
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))
Esempio n. 7
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))
Esempio n. 8
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')
Esempio n. 9
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))
Esempio n. 10
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))
Esempio n. 11
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)
Esempio n. 12
0
    def test_float_set(self):
        interp = Interpreter()

        interp.eval('set x 12.34')

        self.assertEqual(interp.get('x'), 12.34)
Esempio n. 13
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))
Esempio n. 14
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')
Esempio n. 15
0
    def test_simple_set_script_string_single_quote(self):
        interp = Interpreter()

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

        self.assertEqual(interp.get('x'), '5')
Esempio n. 16
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')
Esempio n. 17
0
    def test_simple_set_script_string(self):
        interp = Interpreter()

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

        self.assertEqual(interp.get('x'), '5')
Esempio n. 18
0
    def test_simple_set_script_integer(self):
        interp = Interpreter()

        interp.eval('set x 5')

        self.assertEqual(interp.get('x'), 5)