Example #1
0
def test_module_freeze_self_disk(modules_dir, modules_repo, capsys):
    coroot = install_project(modules_dir, "projectA")

    def verify():
        out, err = capsys.readouterr()

        assert len(err) == 0, err
        assert len(out) == 0, out

        modpath = os.path.join(coroot, "libs/modC/module.yml")
        assert os.path.getsize(os.path.join(coroot, "project.yml")) != 0
        assert os.path.getsize(modpath) != 0

        with open(modpath, "r", encoding="utf-8") as fh:
            outf = fh.read()
            assert outf == ("""name: modC
license: Apache 2.0
version: '3.2'
requires:
- modE ~= 3.2
- modF ~= 3.2
- modI ~= 3.2
- std ~= 3.2
""")

    modp = os.path.join(coroot, "libs/modC")
    app(["module", "install"])
    os.chdir(modp)
    os.curdir = modp
    app(["module", "freeze"])
    verify()
Example #2
0
def test_project_freeze_bad(modules_dir, modules_repo, capsys, caplog):
    coroot = install_project(modules_dir, "baddep", config=False)

    with pytest.raises(CLIException) as e:
        app(["project", "freeze"])

    assert e.value.exitcode == 1
    assert str(e.value) == "Could not load project"

    out, err = capsys.readouterr()

    assert len(err) == 0, err
    assert len(out) == 0, out
    assert "requirement mod2<2016 on module mod2 not fullfilled, now at version 2016.1" in caplog.text

    assert os.path.getsize(os.path.join(coroot, "project.yml")) != 0
Example #3
0
def test_project_options_in_config(modules_dir, modules_repo, capsys):
    coroot = install_project(modules_dir, "projectA")
    with open("project.yml", "w", encoding="utf-8") as fh:
        fh.write("""name: projectA
license: Apache 2.0
version: 0.0.1
modulepath: libs
downloadpath: libs
repo: %s
freeze_recursive: true
freeze_operator: ==
""" % modules_repo)

    def verify():
        out, err = capsys.readouterr()

        assert os.path.getsize(os.path.join(coroot, "project.yml")) != 0
        assert len(err) == 0, err
        assert len(out) == 0, out

        with open("project.yml", "r", encoding="utf-8") as fh:
            assert fh.read() == ("""name: projectA
license: Apache 2.0
version: 0.0.1
modulepath: libs
downloadpath: libs
repo: %s
freeze_recursive: true
freeze_operator: ==
requires:
- modB == 3.2
- modC == 3.2
- modD == 3.2
- modE == 3.2
- modF == 3.2
- modG == 3.2
- modH == 3.2
- modJ == 3.2
- std == 3.2
""" % modules_repo)

    app(["project", "freeze"])
    verify()
    app(["project", "freeze"])
    verify()
Example #4
0
def test_module_freeze(modules_dir, modules_repo, capsys):
    coroot = install_project(modules_dir, "projectA")

    def verify():
        out, err = capsys.readouterr()

        assert os.path.getsize(os.path.join(coroot, "project.yml")) != 0
        assert len(err) == 0, err
        assert out == ("""name: modC
license: Apache 2.0
version: '3.2'
requires:
- modE ~= 3.2
- modF ~= 3.2
- modI ~= 3.2
- std ~= 3.2
""")

    app(["module", "-m", "modC", "freeze", "-o", "-"])
    verify()
Example #5
0
def test_project_freeze(modules_dir, modules_repo, capsys):
    coroot = install_project(modules_dir, "projectA")

    app(["project", "freeze", "-o", "-"])

    out, err = capsys.readouterr()

    assert os.path.getsize(os.path.join(coroot, "project.yml")) != 0
    assert len(err) == 0, err
    assert (out == """name: projectA
license: Apache 2.0
version: 0.0.1
modulepath: libs
downloadpath: libs
repo: %s
requires:
- modB ~= 3.2
- modC ~= 3.2
- modD ~= 3.2
- std ~= 3.2
""" % modules_repo)
def test_module_corruption(modules_dir, modules_repo):
    mod9 = make_module_simple(modules_repo, "mod9", [("mod10", None)])
    add_file(mod9, "signal", "present", "third commit", version="3.3")
    add_file(mod9, "model/b.cf", "import mod9", "fourth commit", version="4.0")

    mod10 = make_module_simple(modules_repo, "mod10", [])
    add_file(mod10, "signal", "present", "a commit", version="3.3")
    # syntax error
    add_file(mod10, "model/_init.cf", "SomeInvalidThings", "a commit", version="3.5")
    # fix it
    add_file(mod10, "model/_init.cf", "", "a commit", version="3.6")
    add_file(mod10, "secondsignal", "import mod9", "b commit", version="4.0")
    add_file(mod10, "badsignal", "import mod9", "c commit", version="5.0")

    p9 = makeproject(modules_repo, "proj9", [("mod9", "==3.3"), ("mod10", "==3.3")], ["mod9"])
    commitmodule(p9, "first commit")

    # setup project
    proj = install_project(modules_dir, "proj9")
    app(["modules", "install"])
    print(os.listdir(proj))

    # unfreeze deps to allow update
    projectyml = os.path.join(proj, "project.yml")
    assert os.path.exists(projectyml)

    with open(projectyml, "r", encoding="utf-8") as fh:
        pyml = yaml.load(fh)

    pyml["requires"] = ["mod10 == 3.5"]

    with open(projectyml, "w", encoding="utf-8") as fh:
        yaml.dump(pyml, fh)

    # clear cache
    Project._project = None

    # attempt to update, mod10 is wrong, but only after the update
    app(["modules", "update"])

    with pytest.raises(ParserException):
        # clear cache
        Project._project = None
        # attempt to update, mod10 is wrong, can not be fixed
        app(["modules", "update"])

    # unfreeze deps to allow update
    pyml["requires"] = ["mod10 == 4.0"]

    with open(projectyml, "w", encoding="utf-8") as fh:
        yaml.dump(pyml, fh)

    # overwrite main to import unknown sub module
    main = os.path.join(proj, "main.cf")
    assert os.path.exists(main)

    with open(main, "w", encoding="utf-8") as fh:
        fh.write("import mod9::b")

    # clear cache
    Project._project = None

    # attempt to update
    app(["modules", "update"])

    # Additional output
    Project._project = None
    app(["modules", "list"])

    # Verify
    m9dir = os.path.join(proj, "libs", "mod9")
    assert os.path.exists(os.path.join(m9dir, "model", "b.cf"))
    m10dir = os.path.join(proj, "libs", "mod10")
    assert os.path.exists(os.path.join(m10dir, "secondsignal"))
    # should not be lastest version
    assert not os.path.exists(os.path.join(m10dir, "badsignal"))