Esempio n. 1
0
    def test_parsed_py_file_by_module(self):
        classes = ParsedClass.get_parsed_classes(browser)
        self.assertGreaterEqual(len(classes), 1)

        _class = classes[0]
        self.assertIn('FF', _class.fields)
        self.assertEqual(_class.get_value('FF'), 'ff')
        self.assertEqual(_class.get_code('type'),
                         inspect.getsource(browser.Browser.type))
        self.assertEqual(_class.get_arg_spec('type').args,
                         ['self', 'element', 'text'])
    def test_parsed_py_file_by_module(self):
        classes = ParsedClass.get_parsed_classes(browser)
        self.assertGreaterEqual(len(classes), 1)

        _class = classes[0]
        self.assertIn('FF', _class.fields)
        self.assertEqual(_class.get_value('FF'), 'ff')
        self.assertEqual(_class.get_code('type'),
                         inspect.getsource(browser.Browser.type))
        self.assertEqual(
            _class.get_arg_spec('type').args, ['self', 'element', 'text'])
Esempio n. 3
0
    def test_parsed_py_file_by_path(self):
        path = os.path.abspath(os.path.join(__file__, '..', '..', 'browser.py'))
        classes = ParsedClass.get_parsed_classes(path)
        self.assertGreaterEqual(len(classes), 1)

        _class = classes[0]
        self.assertIn('FF', _class.fields)
        self.assertEqual(_class.get_value('FF'), 'ff')
        self.assertEqual(_class.get_code('type'),
                         inspect.getsource(browser.Browser.type))
        self.assertEqual(_class.get_arg_spec('type').args,
                         ['self', 'element', 'text'])

        self.assertEqual(path, _class.get_source_file())
    def test_parsed_py_file_by_path(self):
        path = os.path.abspath(os.path.join(__file__, '..', '..',
                                            'browser.py'))
        classes = ParsedClass.get_parsed_classes(path)
        self.assertGreaterEqual(len(classes), 1)

        _class = classes[0]
        self.assertIn('FF', _class.fields)
        self.assertEqual(_class.get_value('FF'), 'ff')
        self.assertEqual(_class.get_code('type'),
                         inspect.getsource(browser.Browser.type))
        self.assertEqual(
            _class.get_arg_spec('type').args, ['self', 'element', 'text'])

        self.assertEqual(path, _class.get_source_file())
Esempio n. 5
0
    def __load_tests_to_tree(self, file_paths=None, dir_path=None):
        if file_paths:
            python_files = file_paths
        elif dir_path:
            python_files = [f for f in get_list_of_files(dir_path, True)]
        else:
            python_files = []

        python_files = [
            f for f in python_files if 'test' in os.path.basename(f)
            and os.path.splitext(f)[-1] == '.py'
        ]
        if len(python_files) > 0:
            syspath = list(os.sys.path)
            try:
                root_folder = self.__get_safe_path_from_root_folder()

                if root_folder not in os.sys.path:
                    os.sys.path.append(root_folder)

                checkbox_type = 1
                self.tree_ctrl.DeleteAllItems()
                root = self.tree_ctrl.AddRoot('All test cases', checkbox_type)

                for python_file in python_files:
                    top_item = self.tree_ctrl.AppendItem(
                        root, os.path.abspath(python_file), checkbox_type)

                    parsed_classes = ParsedClass.get_parsed_classes(
                        python_file)
                    for parsed_class in parsed_classes:
                        item = self.tree_ctrl.AppendItem(
                            top_item, parsed_class.name, checkbox_type)

                        test_methods = [
                            k for k in parsed_class.methods.keys()
                            if k.startswith('test_')
                        ]
                        for tc_name in test_methods:
                            self.tree_ctrl.AppendItem(item, tc_name,
                                                      checkbox_type)

                self.tree_ctrl.ExpandAll()
            except Exception:
                show_error_dialog(self, traceback.format_exc(),
                                  'Cannot add test cases')
            finally:
                os.sys.path = syspath
Esempio n. 6
0
    def __load_tests_to_tree(self, file_paths=None, dir_path=None):
        if file_paths:
            python_files = file_paths
        elif dir_path:
            python_files = [f for f in get_list_of_files(dir_path, True)]
        else:
            python_files = []

        python_files = [f for f in python_files
                        if 'test' in os.path.basename(f) and os.path.splitext(f)[-1] == '.py']
        if len(python_files) > 0:
            syspath = list(os.sys.path)
            try:
                root_folder = self.__get_safe_path_from_root_folder()

                if root_folder not in os.sys.path:
                    os.sys.path.append(root_folder)

                checkbox_type = 1
                self.tree_ctrl.DeleteAllItems()
                root = self.tree_ctrl.AddRoot('All test cases', checkbox_type)

                for python_file in python_files:
                    top_item = self.tree_ctrl.AppendItem(root, os.path.abspath(python_file), checkbox_type)

                    parsed_classes = ParsedClass.get_parsed_classes(python_file)
                    for parsed_class in parsed_classes:
                        item = self.tree_ctrl.AppendItem(top_item, parsed_class.name, checkbox_type)

                        test_methods = [k for k in parsed_class.methods.keys() if k.startswith('test_')]
                        for tc_name in test_methods:
                            self.tree_ctrl.AppendItem(item, tc_name, checkbox_type)

                self.tree_ctrl.ExpandAll()
            except Exception:
                show_error_dialog(self,
                                  traceback.format_exc(),
                                  'Cannot add test cases')
            finally:
                os.sys.path = syspath