示例#1
0
    def test_retrieving_classes_from_file_with_error(self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        module_location = os.path.join(parent_path,
                                       'res_test_red_module_classes',
                                       'error.py')

        with self.assertRaises(SyntaxError) as cm:
            get_classes_from_module(module_location)
示例#2
0
    def test_retrieving_classes_from_file_with_cycle(self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        module_location = os.path.join(parent_path,
                                       'res_test_red_module_classes', 'cycle',
                                       'module_a.py')

        import platform
        if 'Jython' in platform.python_implementation():
            with self.assertRaises(ImportError) as cm:
                get_classes_from_module(module_location)
        else:
            result = get_classes_from_module(module_location)
            self.assertEqual(result, ['module_a'])
    def test_retrieving_classes_from_nested_python_module_1(self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        module_location = os.path.join(parent_path,
                                       'res_test_red_module_classes',
                                       'mod_outer', '__init__.py')

        result = get_classes_from_module(module_location)

        import platform
        if 'Jython' in platform.python_implementation():
            self.assertEqual(result, [
                'mod_outer', 'mod_outer.ClassA', 'mod_outer.ClassB',
                'mod_outer.OtherClassA', 'mod_outer.mod_a', 'mod_outer.mod_b',
                'mod_outer.mod_inner', 'mod_outer.mod_inner.mod_a',
                'mod_outer.mod_inner.mod_a.ClassA',
                'mod_outer.mod_inner.mod_a.ClassA.ClassA',
                'mod_outer.mod_inner.mod_a.OtherClassA',
                'mod_outer.mod_inner.mod_a.OtherClassA.OtherClassA',
                'mod_outer.mod_inner.mod_a.mod_a', 'mod_outer.mod_inner.mod_b',
                'mod_outer.mod_inner.mod_b.ClassB',
                'mod_outer.mod_inner.mod_b.ClassB.ClassB',
                'mod_outer.mod_inner.mod_b.mod_b'
            ])
        else:
            self.assertEqual(result, [
                'mod_outer', 'mod_outer.mod_inner',
                'mod_outer.mod_inner.mod_a',
                'mod_outer.mod_inner.mod_a.ClassA',
                'mod_outer.mod_inner.mod_a.ClassA.ClassA',
                'mod_outer.mod_inner.mod_a.OtherClassA',
                'mod_outer.mod_inner.mod_a.OtherClassA.OtherClassA',
                'mod_outer.mod_inner.mod_b',
                'mod_outer.mod_inner.mod_b.ClassB',
                'mod_outer.mod_inner.mod_b.ClassB.ClassB'
            ])
示例#4
0
    def test_retrieving_classes_from_empty_file(self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        module_location = os.path.join(parent_path,
                                       'res_test_red_module_classes',
                                       'empty.py')

        result = get_classes_from_module(module_location)

        self.assertEqual(result, ['empty'])
示例#5
0
    def test_retrieving_classes_from_file_with_same_class_name(self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        module_location = os.path.join(parent_path,
                                       'res_test_red_module_classes',
                                       'ClassName.py')

        result = get_classes_from_module(module_location)

        self.assertEqual(result, ['ClassName', 'ClassName.ClassName'])
示例#6
0
    def test_retrieving_classes_from_file_with_several_methods_and_documentation(
            self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        module_location = os.path.join(parent_path,
                                       'res_test_red_module_classes',
                                       'docs_and_methods.py')

        result = get_classes_from_module(module_location)

        self.assertEqual(result, ['docs_and_methods'])
示例#7
0
    def test_retrieving_classes_from_module_with_relative_imports(self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        module_location = os.path.join(parent_path,
                                       'res_test_red_module_classes',
                                       'relative_import', '__init__.py')

        result = get_classes_from_module(module_location)

        self.assertEqual(result,
                         ['relative_import', 'relative_import.non_relative'])
示例#8
0
    def test_retrieving_classes_from_python_module_with_init_only(self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        module_location = os.path.join(parent_path,
                                       'res_test_red_module_classes', 'init',
                                       '__init__.py')

        result = get_classes_from_module(module_location)

        self.assertEqual(result,
                         ['init', 'init.InitClass', 'init.OtherInitClass'])
示例#9
0
    def test_retrieving_classes_from_unicode_named_module(self):
        #For python2 unicode would not work properly because of its internal problems
        parent_path = os.path.dirname(os.path.realpath(__file__))
        module_location = os.path.join(parent_path,
                                       'res_test_red_module_classes',
                                       'UnicodeClass.py')

        result = get_classes_from_module(module_location)

        self.assertEqual(result, ['UnicodeClass', 'UnicodeClass.UnicodeClass'])
示例#10
0
    def test_retrieving_classes_from_python_module_in_zip(self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        module_location = os.path.join(parent_path,
                                       'res_test_red_module_classes',
                                       'compressed.zip')

        result = get_classes_from_module(module_location, None)

        self.assertEqual(
            result,
            ['compressed.mod_compressed_1', 'compressed.mod_compressed_2'])
示例#11
0
    def test_retrieving_classes_from_file_with_several_classes(self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        module_location = os.path.join(parent_path,
                                       'res_test_red_module_classes',
                                       'several_classes.py')

        result = get_classes_from_module(module_location)

        self.assertEqual(result, [
            'several_classes', 'several_classes.First',
            'several_classes.Second', 'several_classes.Third'
        ])
示例#12
0
    def test_retrieving_classes_from_python_module_with_init_2(self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        module_location = os.path.join(parent_path,
                                       'res_test_red_module_classes', 'module',
                                       '__init__.py')

        result = get_classes_from_module(module_location, None)

        self.assertEqual(result, [
            'module', 'ModuleClass', 'OtherModuleClass', 'module.ModuleClass',
            'module.OtherModuleClass'
        ])
示例#13
0
    def test_retrieving_classes_from_file_with_different_name_inside_module(
            self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        module_location = os.path.join(parent_path,
                                       'res_test_red_module_classes',
                                       'module_diff_names',
                                       'DifferentModuleClassName.py')

        result = get_classes_from_module(module_location)

        self.assertEqual(result, [
            'module_diff_names.DifferentModuleClassName',
            'module_diff_names.DifferentModuleClassName.OtherClassName'
        ])
示例#14
0
    def test_retrieving_classes_from_python_module_in_jar(self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        module_location = os.path.join(parent_path,
                                       'res_test_red_module_classes',
                                       'JythonLibWithPython.jar')

        result = get_classes_from_module(module_location)

        import platform
        if 'Jython' in platform.python_implementation():
            self.assertEqual(
                result, ['PythonOnly', 'PythonOnly.Other', 'PythonWithJava'])
        else:
            self.assertEqual(result, ['PythonOnly', 'PythonOnly.Other'])
示例#15
0
    def test_retrieving_classes_from_file_in_directory_with_same_name_like_sys_module(
            self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        module_location = os.path.join(parent_path,
                                       'res_test_red_module_classes', 'robot',
                                       'CustomRobotClassName.py')

        result = get_classes_from_module(module_location)

        self.assertEqual(result, [
            'CustomRobotClassName',
            'CustomRobotClassName.CustomRobotClassName',
            'robot.CustomRobotClassName',
            'robot.CustomRobotClassName.CustomRobotClassName'
        ])
示例#16
0
    def test_retrieving_classes_from_module_with_relative_imports(self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        module_location = os.path.join(parent_path,
                                       'res_test_red_module_classes',
                                       'relative_import', '__init__.py')

        result = get_classes_from_module(module_location)

        import platform
        if 'Jython' in platform.python_implementation():
            self.assertEqual(
                result, ['relative_import', 'relative_import.non_relative'])
        else:
            self.assertEqual(result, [
                'relative_import', 'relative_import.non_relative',
                'relative_import.relative', 'relative_import.relative.Relative'
            ])
示例#17
0
    def test_retrieving_classes_from_nested_python_module_3(self):
        parent_path = os.path.dirname(os.path.realpath(__file__))
        module_location = os.path.join(parent_path,
                                       'res_test_red_module_classes',
                                       'mod_outer', 'mod_inner', 'mod_a',
                                       '__init__.py')

        result = get_classes_from_module(module_location)

        self.assertEqual(result, [
            'mod_a', 'mod_a.ClassA', 'mod_a.ClassA.ClassA',
            'mod_a.OtherClassA', 'mod_a.OtherClassA.OtherClassA',
            'mod_a.mod_a', 'mod_inner.mod_a', 'mod_inner.mod_a.ClassA',
            'mod_inner.mod_a.ClassA.ClassA', 'mod_inner.mod_a.OtherClassA',
            'mod_inner.mod_a.OtherClassA.OtherClassA', 'mod_inner.mod_a.mod_a',
            'mod_outer.mod_inner.mod_a', 'mod_outer.mod_inner.mod_a.ClassA',
            'mod_outer.mod_inner.mod_a.ClassA.ClassA',
            'mod_outer.mod_inner.mod_a.OtherClassA',
            'mod_outer.mod_inner.mod_a.OtherClassA.OtherClassA',
            'mod_outer.mod_inner.mod_a.mod_a'
        ])
示例#18
0
def get_classes_from_module(module_location, python_paths, class_paths):
    import red_module_classes
    __extend_paths(python_paths, class_paths)
    return red_module_classes.get_classes_from_module(module_location)