Example #1
0
def test_get_target_config_no_cfg():
    """
    Test get target config if config does not exist
    """
    path = Path("/foo/bar")
    setattr(path.__class__, "exists", MagicMock(return_value=False))
    result = get_target_config(path)
    assert result == []
Example #2
0
def test_get_target_cfg_empty_cfg():
    """
    Test get target config if config is empty
    """
    with patch("molior.molior.core.Configuration") as mock:
        cfg = MagicMock()
        cfg.config.return_value = {}
        mock.return_value = cfg

        path = Path("/foo/bar")
        setattr(path.__class__, "exists", MagicMock(return_value=True))
        result = get_target_config(path)
        assert result == []
Example #3
0
def test_get_target_config():
    """
    Test get target config
    """
    with patch("molior.molior.core.Configuration") as mock:
        cfg = MagicMock()
        cfg.config.return_value = {"targets": {"testproject": ["1", "next"]}}
        mock.return_value = cfg

        path = Path("/foo/bar")
        setattr(path.__class__, "exists", MagicMock(return_value=True))
        result = get_target_config(path)
        assert set(result).issubset([("testproject", "1"),
                                     ("testproject", "next")])
Example #4
0
async def GetBuildInfo(repo_path, git_ref):
    class BuildInfo:
        pass

    info = BuildInfo()
    info.version = await get_changelog_attr("Version", repo_path)
    info.sourcename = await get_changelog_attr("Source", repo_path)

    gitinfo = None

    async def outh(line):
        nonlocal gitinfo
        gitinfo = line.strip()

    process = Launchy(shlex.split("git show -s --format='%H %cI %ae %an'"),
                      outh,
                      outh,
                      cwd=str(repo_path))
    await process.launch()
    await process.wait()

    gitinfos = gitinfo.split(" ", 3)
    if len(gitinfos) != 4:
        logger.error("Error parsing git info '%s'", gitinfos)
        return None

    info.commit_hash = gitinfos[0]
    d = gitinfos[1]
    info.author_email = gitinfos[2]
    info.author_name = gitinfos[3]

    ts = d[0:19] + d[19:25].replace(":", "")
    tag_dt = datetime.strptime(ts, "%Y-%m-%dT%H:%M:%S%z")

    info.tag_stamp = tag_dt.strftime("%Y-%m-%d %T%z")
    info.tag_dt = tag_dt

    try:
        info.firstname, info.lastname, info.email = await get_maintainer(
            repo_path)
    except MaintainerParseError as exc:
        logger.warning("could not get maintainer: %s" % str(exc))
        return None

    info.plain_targets = get_target_config(repo_path)

    return info