Esempio n. 1
0
    def test_subsequent_calls_for_same_variable_file_name_under_different_paths_return_different_variables(self):
        parent_path = os.path.dirname(os.path.realpath(__file__))

        response1 = get_variables(os.path.join(parent_path, 'res_test_robot_session_server', 'a', 'vars.py'), [])
        response2 = get_variables(os.path.join(parent_path, 'res_test_robot_session_server', 'b', 'vars.py'), [])

        self.assertNotEqual(response1, response2)
 def test_variables_are_returned_for_variables_file_reading_another_file_by_relative_path(self):
     parent_path = os.path.dirname(os.path.realpath(__file__))
     
     response = get_variables(os.path.join(parent_path, 'res_test_robot_session_server', 'vars_modules', 'vars_loading.py'), [], [])
     
     self.assertTrue(response['exception'] is None)
     self.assertDictEqual(response['result'], {'a':'10', 'b':'20'})
 def test_variables_are_returned_for_yaml_variables_file(self):
     parent_path = os.path.dirname(os.path.realpath(__file__))
     
     response = get_variables(os.path.join(parent_path, 'res_test_robot_session_server', 'vars_modules', 'vars.yaml'), [], [])
     
     self.assertTrue(response['exception'] is None)
     self.assertDictEqual(response['result'], {'a':'1', 'b':'2', 'c':'3'})
    def test_variables_are_not_returned_for_variable_file_importing_module_not_visible_in_pythonpath(self):
        parent_path = os.path.dirname(os.path.realpath(__file__))

        response = get_variables(os.path.join(parent_path, 'res_test_robot_session_server', 'vars_modules', 'a', 'b.py'), [], [])
        
        self.assertIn('Traceback', response['exception'])
        self.assertTrue(response['result'] is None)
    def test_variables_are_returned_for_variable_file_importing_module_visible_in_pythonpath(self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        additional_path = os.path.join(parent_path, 'res_test_robot_session_server', 'vars_modules')

        response = get_variables(os.path.join(parent_path, 'res_test_robot_session_server', 'vars_modules', 'a', 'b.py'), [], [additional_path])
        
        self.assertTrue(response['exception'] is None)
        self.assertDictEqual(response['result'], {'x':'1', 'y':'2', 'z':'3'})
    def test_if_empty_result_is_returned_for_empty_file(self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        vars_location = os.path.join(parent_path,
                                     'res_test_robot_session_server',
                                     'variables', 'empty.py')

        response = get_variables(vars_location, [])

        self.assertEqual(response, {'result': {}, 'exception': None})
    def test_if_syntax_error_is_returned_for_file_with_error(self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        vars_location = os.path.join(parent_path,
                                     'res_test_robot_session_server',
                                     'variables', 'vars_with_syntax.py')

        response = get_variables(vars_location, [])

        self.assertEqual(response['result'], None)
        self.assertTrue('SyntaxError: ' in response['exception'],
                        'Exception stack trace should contain SyntaxError')
    def test_if_data_error_is_returned_for_file_with_unsupported_extension(
            self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        vars_location = os.path.join(parent_path,
                                     'res_test_robot_session_server',
                                     'variables', 'vars_in_unsupported.robot')

        response = get_variables(vars_location, [])

        self.assertEqual(response['result'], None)
        self.assertTrue('DataError: ' in response['exception'],
                        'Exception stack trace should contain DataError')
    def test_if_result_is_returned_for_vars_in_method(self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        vars_location = os.path.join(parent_path,
                                     'res_test_robot_session_server',
                                     'variables', 'vars_in_method.py')

        response = get_variables(vars_location, [])

        self.assertEqual(response, {
            'result': {
                'a': '1',
                'b': '2',
                'c': '3'
            },
            'exception': None
        })
Esempio n. 10
0
    def test_if_result_is_returned_for_vars_in_lines(self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        vars_location = os.path.join(parent_path,
                                     'res_test_robot_session_server',
                                     'variables', 'vars_in_lines.py')

        response = get_variables(vars_location, [])

        self.assertEqual(
            response, {
                'result': {
                    'first': '123',
                    'second': '234',
                    'third': '345'
                },
                'exception': None
            })