Exemple #1
0
    def tests(self):
        """Return a list with all the test cases in the suite"""
        # TODO should use glob
        tests = []
        module = self.get_module()

        if not hasattr(module, 'tests'):
            return tests

        project = Project(self.project)
        if '*' in module.tests:
            tests = project.tests()
        else:
            for test in module.tests:
                if test.endswith('.*'):
                    this_dir = test[:-2]
                    path = os.path.join(project.test_directory_path,
                                        os.sep.join(this_dir.split('.')))
                    this_dir_tests = file_manager.get_files_dot_path(
                        path, extension='.py')
                    this_dir_tests = [
                        '{}.{}'.format(this_dir, x) for x in this_dir_tests
                    ]
                    tests = tests + this_dir_tests
                else:
                    tests.append(test)
        return tests
Exemple #2
0
def get_directory_test_cases(workspace, project, suite):
    '''Return a list with all the test cases of a given directory'''
    tests = list()
    path = os.path.join(workspace, 'projects', project, 'tests', suite)
    files = file_manager.get_files_dot_path(path, extension='.py')
    tests = ['.'.join((suite, x)) for x in files]
    return tests
Exemple #3
0
def get_directory_tests(workspace, project, directory):
    """Return a list with all the test cases of a given directory"""
    path = os.path.join(workspace, 'projects', project, 'tests', directory)
    tests = file_manager.get_files_dot_path(path, extension='.py')
    if directory:
        dotpath = '.'.join(os.path.normpath(directory).split(os.sep))
        tests = ['.'.join([dotpath, x]) for x in tests]
    return tests
 def test_get_files_dot_path(self, project_function):
     _, project = project_function.activate()
     page_object.new_page_object(project, [], 'page1')
     page_object.new_page_object(project, ['dir', 'subdir'], 'page2')
     base_path = os.path.join(project_function.path, 'pages')
     dot_files = file_manager.get_files_dot_path(base_path)
     expected_result = ['page1', 'dir.subdir.page2']
     assert dot_files == expected_result
 def test_get_files_dot_path_with_extension(self, project_function):
     _, project = project_function.activate()
     page_object.new_page_object(project, [], 'page2')
     base_path = os.path.join(project_function.path, 'pages')
     another_extension = os.path.join(base_path, 'another.json')
     open(another_extension, 'w+').close()
     dot_files = file_manager.get_files_dot_path(base_path, extension='.py')
     expected_result = ['page2']
     assert dot_files == expected_result
Exemple #6
0
 def test_get_files_dot_path_with_extension(self, project_function):
     testdir = project_function['testdir']
     project = project_function['name']
     page_object.new_page_object(testdir, project, [], 'page2')
     base_path = os.path.join(testdir, 'projects', project, 'pages')
     another_extension = os.path.join(base_path, 'another.json')
     open(another_extension, 'w+').close()
     dot_files = file_manager.get_files_dot_path(base_path, extension='.py')
     expected_result = ['page2']
     assert dot_files == expected_result
Exemple #7
0
def get_suite_test_cases(workspace, project, suite):
    """Return a list with all the test cases of a given suite"""
    tests = []
    module_name = 'projects.{0}.suites.{1}'.format(project, suite)
    suite_module = importlib.import_module(module_name, package=None)
    if '*' in suite_module.tests:
        path = os.path.join(workspace, 'projects', project, 'tests')
        tests = file_manager.get_files_dot_path(path)
    else:
        for test in suite_module.tests:
            if test[-1] == '*':
                this_dir = os.path.join(test[:-2])
                path = os.path.join(workspace, 'projects', project,
                                    'tests', this_dir)
                this_dir_tests = file_manager.get_files_dot_path(path)
                this_dir_tests = ['{}.{}'.format(this_dir, x) for x in this_dir_tests]
                tests = tests + this_dir_tests
            else:
                tests.append(test)
    return tests
Exemple #8
0
def get_suite_test_cases(workspace, project, suite):
    """Return a list with all the test cases of a given suite"""
    # TODO should use glob
    tests = []
    suite_module = get_suite_module(workspace, project, suite)
    if '*' in suite_module.tests:
        path = os.path.join(workspace, 'projects', project, 'tests')
        tests = file_manager.get_files_dot_path(path, extension='.py')
    else:
        for test in suite_module.tests:
            if test[-1] == '*':
                this_dir = os.path.join(test[:-2])
                path = os.path.join(workspace, 'projects', project,
                                    'tests', this_dir)
                this_dir_tests = file_manager.get_files_dot_path(path, extension='.py')
                this_dir_tests = ['{}.{}'.format(this_dir, x) for x in this_dir_tests]
                tests = tests + this_dir_tests
            else:
                tests.append(test)
    return tests
Exemple #9
0
 def _file_list(self, file_type, directory=''):
     """List of files of `file_type`.
     Directory must be a relative path from the project element base folder
     """
     base_path = self.element_directory_path(file_type)
     path = os.path.join(base_path, directory)
     elements = file_manager.get_files_dot_path(path, extension='.py')
     if directory:
         dotpath = '.'.join(os.path.normpath(directory).split(os.sep))
         elements = ['.'.join([dotpath, x]) for x in elements]
     return elements
Exemple #10
0
 def test_get_files_dot_path(self, project_function):
     testdir = project_function['testdir']
     project = project_function['name']
     page_object.new_page_object(testdir, project, [], 'page1')
     page_object.new_page_object(testdir, project, ['dir', 'subdir'], 'page2')
     base_path = os.path.join(testdir, 'projects', project, 'pages')
     dot_files = file_manager.get_files_dot_path(base_path)
     expected_result = [
         'page1',
         'dir.subdir.page2'
     ]
     assert dot_files == expected_result
 def test_get_files_dot_path(self, testdir_fixture):
     project = helper_functions.create_random_project(
         testdir_fixture['path'])
     # create a new page object in pages folder
     page_object.new_page_object(testdir_fixture['path'], project, [],
                                 'page1')
     # create a new page object in pages/dir/subdir/
     page_object.new_page_object(testdir_fixture['path'], project,
                                 ['dir', 'subdir'], 'page2')
     base_path = os.path.join(testdir_fixture['path'], 'projects', project,
                              'pages')
     dot_files = file_manager.get_files_dot_path(base_path)
     expected_result = ['page1', 'dir.subdir.page2']
     assert dot_files == expected_result
Exemple #12
0
def get_suite_test_cases(project, suite):
    """Return a list with all the test cases of a given suite"""
    # TODO should use glob
    tests = []
    suite_module = get_suite_module(project, suite)
    if '*' in suite_module.tests:
        path = os.path.join(session.testdir, 'projects', project, 'tests')
        tests = file_manager.get_files_dot_path(path, extension='.py')
    else:
        for test in suite_module.tests:
            if test.endswith('.*'):
                this_dir = test[:-2]
                path = os.path.join(session.testdir, 'projects', project,
                                    'tests', os.sep.join(this_dir.split('.')))
                this_dir_tests = file_manager.get_files_dot_path(
                    path, extension='.py')
                this_dir_tests = [
                    '{}.{}'.format(this_dir, x) for x in this_dir_tests
                ]
                tests = tests + this_dir_tests
            else:
                tests.append(test)
    return tests
Exemple #13
0
 def test_get_files_dot_path_extension(self, testdir_fixture):
     project = helper_functions.create_random_project(testdir_fixture['path'])
     testdir = testdir_fixture['path']
     # create a new page object in pages folder (.py extension)
     page_object.new_page_object(testdir, project, [], 'page2')
     # create a file with another extension
     another_extension = os.path.join(testdir, 'projects', project,
                                      'pages', 'another.json')
     with open(another_extension, 'w') as another_file:
         another_file.write('')
     base_path = os.path.join(testdir_fixture['path'], 'projects',
                              project, 'pages')
     dot_files = file_manager.get_files_dot_path(base_path, extension='.py')
     expected_result = ['page2']
     assert dot_files == expected_result
Exemple #14
0
 def test_get_files_dot_path(self, testdir_fixture):
     project = helper_functions.create_random_project(
         testdir_fixture['path'])
     # create a new page object in pages folder
     page_object.new_page_object(testdir_fixture['path'], project, [],
                                 'page1')
     # create a new page object in pages/dir/subdir/
     page_object.new_page_object(testdir_fixture['path'],
                                 project, ['dir', 'subdir'],
                                 'page2',
                                 add_parents=True)
     base_path = os.path.join(testdir_fixture['path'], 'projects', project,
                              'pages')
     dotted_files = file_manager.get_files_dot_path(base_path)
     assert 'page1' in dotted_files
     assert 'dir.subdir.page2' in dotted_files
     assert len(dotted_files) == 2
Exemple #15
0
def get_page_objects():
    if request.method == 'POST':
        project = request.form['project']
        path = page_object.pages_base_dir(root_path, project)
        page_objects = file_manager.get_files_dot_path(path, extension='.py')
        return json.dumps(page_objects)
def get_all_project_tests_tags(project):
    """Get all the tags of each test in a project"""
    tests_folder_path = os.path.join(session.testdir, 'projects', project,
                                     'tests')
    tests = file_manager.get_files_dot_path(tests_folder_path, extension='.py')
    return get_tests_tags(project, tests)
Exemple #17
0
def get_page_objects():
    if request.method == 'POST':
        project = request.form['project']
        path = os.path.join(root_path, 'projects', project, 'pages')
        page_objects = file_manager.get_files_dot_path(path)
        return json.dumps(page_objects)