def test_if_data_error_is_raised_for_file_with_error(self): parent_path = os.path.dirname(os.path.realpath(__file__)) vars_location = os.path.join(parent_path, 'res_test_red_variables', 'vars_with_syntax.py') with self.assertRaises(DataError) as cm: get_variables(vars_location, []) self.assertTrue('SyntaxError: ' in cm.exception.message)
def test_if_data_error_is_raised_for_not_existing_file(self): parent_path = os.path.dirname(os.path.realpath(__file__)) vars_location = os.path.join(parent_path, 'res_test_red_variables', 'not_existing.py') with self.assertRaises(DataError) as cm: get_variables(vars_location, []) self.assertTrue( 'File or directory does not exist' in cm.exception.message)
def test_if_data_error_is_raised_for_file_with_unsupported_extension(self): parent_path = os.path.dirname(os.path.realpath(__file__)) vars_location = os.path.join(parent_path, 'res_test_red_variables', 'vars_in_unsupported.robot') with self.assertRaises(DataError) as cm: get_variables(vars_location, []) self.assertTrue( 'Not a valid file or directory to import' in cm.exception.message)
def test_if_result_is_returned_for_vars_with_argument(self): parent_path = os.path.dirname(os.path.realpath(__file__)) vars_location = os.path.join(parent_path, 'res_test_red_variables', 'vars_with_argument.py') result = get_variables(vars_location, ['_arg']) self.assertEqual(result, {'a': '1_arg', 'b': '2_arg', 'c': '3_arg'})
def test_if_result_is_returned_for_vars_in_class(self): parent_path = os.path.dirname(os.path.realpath(__file__)) vars_location = os.path.join(parent_path, 'res_test_red_variables', 'vars_in_class.py') result = get_variables(vars_location, []) self.assertEqual(result, {'x': '9', 'y': '8', 'z': '7'})
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_red_variables', 'vars_in_method.py') result = get_variables(vars_location, []) self.assertEqual(result, {'a': '1', 'b': '2', 'c': '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_red_variables', 'empty.py') result = get_variables(vars_location, []) self.assertEqual(result, {})
def test_if_result_is_returned_with_defined_classes_visible_as_variables( self): parent_path = os.path.dirname(os.path.realpath(__file__)) vars_location = os.path.join(parent_path, 'res_test_red_variables', 'vars_class_as_var.py') result = get_variables(vars_location, []) self.assertSetEqual(set(result.keys()), set(['SomeClass']))
def get_variables(path, args, python_paths): import os cwd = os.getcwd() try: os.chdir(os.path.dirname(path)) import red_variables __extend_paths(python_paths, []) return red_variables.get_variables(path, args) finally: os.chdir(cwd)
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_red_variables', 'vars_in_lines.py') result = get_variables(vars_location, []) self.assertEqual(result, { 'first': '123', 'second': '234', 'third': '345' })
def test_if_result_is_returned_for_vars_with_proper_casing(self): parent_path = os.path.dirname(os.path.realpath(__file__)) vars_location = os.path.join(parent_path, 'res_test_red_variables', 'vars_with_case_sensitive_names.py') result = get_variables(vars_location, []) self.assertEqual( result, { 'first': '123', 'SECOND': '234', 'ThIrD': '345', 'FORTH_with_UnderSCORES': '456' })
def get_variables(dir, args): import red_variables return red_variables.get_variables(dir, args)
def get_variables(path, args): import red_variables return red_variables.get_variables(path, args)
def get_variables(path, args, python_paths): import red_variables __extend_paths(python_paths, []) return red_variables.get_variables(path, args)