示例#1
0
def test_add_test_mapping_when_project_type_has_no_mappings(
        glotter_yml_projects):
    def test_func():
        pass

    Settings().add_test_mapping('baklava', test_func)
    assert test_func.__name__ in Settings().get_test_mapping_name('baklava')
示例#2
0
文件: download.py 项目: auroq/glotter
def _download_project(project):
    sources_by_type = get_sources(Settings().source_root)
    try:
        Settings().verify_project_type(project)
        sources = sources_by_type[project]
        for source in sources:
            _download_image_from_source(source)
    except KeyError:
        _error_and_exit(f'No valid sources found for project: "{project}"')
示例#3
0
文件: download.py 项目: auroq/glotter
def _download_language(language):
    sources_by_type = get_sources(
        path=os.path.join(Settings().source_root, language[0], language))
    if all([len(sources) <= 0 for _, sources in sources_by_type.items()]):
        _error_and_exit(f'No valid sources found for language: "{language}"')
    for project_type, sources in sources_by_type.items():
        for source in sources:
            _download_image_from_source(source)
示例#4
0
文件: test.py 项目: auroq/glotter
def _run_project(project):
    try:
        Settings().verify_project_type(project)
        tests = _get_tests(project, _collect_tests())
        _verify_test_list_not_empty(tests)
        _run_pytest_and_exit(*tests)
    except KeyError:
        _error_and_exit(
            f'Either tests or sources not found for project: "{project}"')
示例#5
0
    def get_project_mappings(self, include_extension=False):
        """
        Uses the naming scheme to generate the expected source names in the directory
        and create a mapping from ProjectType to source name

        :param include_extension: whether to include the extension in the source name
        :return: a dict where the key is a ProjectType and the value is the source name
        """
        extension = self.extension if include_extension else ''
        return {
            project_type: f'{project.get_project_name_by_scheme(self.naming)}{extension}'
            for project_type, project in Settings().projects.items()
        }
示例#6
0
文件: test.py 项目: auroq/glotter
def _get_tests(project_type, all_tests, src=None):
    test_functions = Settings().get_test_mapping_name(project_type)
    tests = []
    for test_func in test_functions:
        if src is not None:
            filename = f'{src.name}{src.extension}'
            pattern = rf'^(\w/?)*\.py::{test_func}\[{filename}(-.*)?\]$'
        else:
            pattern = rf'^(\w/?)*\.py::{test_func}\[.+\]$'
        tests.extend([
            tst for tst in all_tests if re.fullmatch(pattern, tst) is not None
        ])
    return tests
示例#7
0
文件: report.py 项目: auroq/glotter
    def _collect_language_stats(self):
        language_stats = {}
        sources_by_type = get_sources(Settings().source_root)

        for project, sources in sources_by_type.items():
            display_name = self._get_project_display_name(project)
            for source in sources:
                if source.language not in language_stats:
                    language_stats[source.language] = {
                        p: ''
                        for p in self._projects
                    }
                    language_stats[source.language]['Name'] = source.language
                language_stats[source.language][
                    display_name] = f'{source.name}{source.extension}'

        return language_stats
示例#8
0
def get_sources(path):
    """
    Walk through a directory and create Source objects

    :param path: path to the directory through which to walk
    :return: a dict where the key is the ProjectType and the value is a list of all the Source objects of that project
    """
    sources = {k: [] for k in Settings().projects}
    for root, dirs, files in os.walk(path):
        path = os.path.abspath(root)
        if "testinfo.yml" in files:
            with open(os.path.join(path, 'testinfo.yml'), 'r') as file:
                test_info_string = file.read()
            folder_info = testinfo.FolderInfo.from_dict(
                yaml.safe_load(test_info_string)['folder'])
            folder_project_names = folder_info.get_project_mappings(
                include_extension=True)
            for project_type, project_name in folder_project_names.items():
                if project_name in files:
                    source = Source(project_name, os.path.basename(path), path,
                                    test_info_string)
                    sources[project_type].append(source)
    return sources
示例#9
0
文件: report.py 项目: auroq/glotter
 def _get_project_display_name(key):
     return Settings().projects[key].display_name
示例#10
0
文件: report.py 项目: auroq/glotter
 def __init__(self):
     self._projects = sorted(
         [p.display_name for p in Settings().projects.values()])
     self._language_stats = self._collect_language_stats()
     self._languages = sorted(self._language_stats.keys())
示例#11
0
def test_add_test_mapping_when_project_type_not_in_projects(
        glotter_yml_projects):
    with pytest.raises(KeyError):
        Settings().add_test_mapping('notarealprojectype', None)
示例#12
0
def test_get_test_mapping_name_when_project_type_not_found(
        glotter_yml_projects):
    assert Settings().get_test_mapping_name('nonexistentproject') == []
示例#13
0
文件: download.py 项目: auroq/glotter
def _download_all():
    sources_by_type = get_sources(Settings().source_root)
    for _, sources in sources_by_type.items():
        for source in sources:
            _download_image_from_source(source)