Esempio n. 1
0
def test_guess_name_without_similar_prefix(datadir):

    m = symver.Map()

    with cd(datadir):
        m.read("without_similar_prefix.map")
        name = m.guess_name(None, guess=True)

        # It is expected the name to use the latest release prefix
        assert name == "UNRELATED_NAME_1_2_0"
Esempio n. 2
0
def test_released_map(datadir):
    m = symver.Map()

    with cd(datadir):
        m.read("released.map")

        m.check()

        r = m.releases[0]

        assert r.released
Esempio n. 3
0
def run_script(testcases, datadir, script_runner, capsys, caplog, script):
    for tc in testcases:
        with cd(datadir):
            tc_in = tc["input"]
            tc_out = tc["output"]
            args = tc_in["args"]
            tc_stdin = tc_in["stdin"]

            ret = None
            if tc_stdin:
                with open(tc_stdin, "r") as tcin:
                    # Run the script passing the arguments
                    if args:
                        ret = script_runner.run(script, *args, stdin=tcin)
                    else:
                        ret = script_runner.run(script, stdin=tcin)
                    if not ret.success:
                        print(ret.returncode)
                        print(ret.stdout)
                        print(ret.stderr)
                        assert 0
            else:
                print("Missing input file")
                assert 0

            assert ret.success

            # If there is an expected output to stdout
            if tc_out["stdout"]:
                with open(tc_out["stdout"], "r") as tcout:
                    expected = tcout.read()
                    assert ret.stdout == expected
            else:
                if ret.stdout:
                    print(tc)
                    print("Unexpected output in stdout:\n" + ret.stdout)
                    # Fail
                    assert 0

            # Check if the expected warning messages are in the log
            if tc_out["warnings"]:
                for expected in tc_out["warnings"]:
                    assert expected in caplog.text

            # Check if the expected exception messages are in the log
            if tc_out["exceptions"]:
                for expected in tc_out["exceptions"]:
                    assert expected in caplog.text

            # Clear the log between test cases
            caplog.clear()
Esempio n. 4
0
def test_guess_name_without_prefix(datadir):

    m = symver.Map()
    expected = "".join([
        "Insufficient information to guess the new release",
        " name. Releases found do not have version",
        " information or a valid library name. Please",
        " provide the complete name of the release."
    ])

    with cd(datadir):
        with pytest.raises(Exception) as e:
            m.read("without_prefix.map")
            m.guess_name(None, guess=True)

            assert expected in str(e.value)
Esempio n. 5
0
def test_print_released_map(datadir):
    m = symver.Map()

    with cd(datadir):
        m.read("base.map")

        m.check()

        r = m.releases[0]

        r.released = True

        out = str(m)

        with open("print_released.stdout") as tcout:
            assert out == tcout.read()
Esempio n. 6
0
def test_empty_map(datadir):
    m = symver.Map()

    expected = "Empty map"

    with pytest.raises(Exception) as e:
        m.check()
        assert expected in str(e.value)

    with cd(datadir):
        m.read("base.map")

        m.check()

        out = str(m)

        with open("empty_map.stdout") as tcout:
            assert out == tcout.read()
Esempio n. 7
0
def test_build_bib_inplace(mock_init):
    bm.merge(u.HOME+"examples/sample.bib")
    with cd(u.HOME+'examples'):
        missing = lm.build_bib("sample.tex")
        files = os.listdir(".")
        assert "texsample.bib" in files
        # Now check content:
        np.testing.assert_array_equal(missing, np.zeros(0,dtype="U"))
        bibs = bm.read_file("texsample.bib")
        assert len(bibs) == 8
        keys = [bib.key for bib in bibs]
        assert "AASteamHendrickson2018aastex62" in keys
        assert "HarrisEtal2020natNumpy" in keys
        assert "VirtanenEtal2020natmeScipy" in keys
        assert "Hunter2007ieeeMatplotlib" in keys
        assert "PerezGranger2007cseIPython" in keys
        assert "MeurerEtal2017pjcsSYMPY" in keys
        assert "Astropycollab2013aaAstropy" in keys
        assert "Cubillos2019zndoBibmanager" in keys
Esempio n. 8
0
def test_update_different_program_name(datadir, capsys):
    class C(object):
        """
        Empty class used as a namespace
        """
        pass

    with cd(datadir):
        # Get the arguments parser
        parser = symver.get_arg_parser()

        # Set the options to call the version subcommand
        options = ['update', '-a', '-i', 'symbol.in', "base.map"]

        # Create a namespace and set a custom program name
        ns = C()
        ns.program = 'someapp'

        # Parse arguments
        args = parser.parse_args(options, namespace=ns)

        # Run command and check output
        ns.func(args)
        out, err = capsys.readouterr()
        with open("update_different_name.stdout") as tcout:
            assert out == tcout.read()
        assert not err

        # Create a namespace and set an empty program name
        ns = C()
        ns.program = None

        # Parse arguments
        args = parser.parse_args(options, namespace=ns)

        # Run command and check output
        ns.func(args)
        out, err = capsys.readouterr()
        with open("update_default_name.stdout") as tcout:
            assert out == tcout.read()
        assert not err
Esempio n. 9
0
def run_tc(tc, datadir, capsys, caplog):
    """
    Run a 'check' command test case

    :param tc: The tescase
    :param datadir: The path to the directory where the test input are
    :param capsys: The output capture fixture
    :param caplog: The log capture fixture
    """
    class C(object):
        """
        Empty class used as a namespace
        """
        pass

    # Change directory to the temporary directory
    with cd(datadir):
        # Get a parser
        parser = symver.get_arg_parser()

        tc_in = tc["input"]
        tc_out = tc["output"]

        # Add the simulated program name
        ns = C()
        ns.program = 'abimap'

        # Parse the testcase arguments
        args = parser.parse_args(tc_in["args"], namespace=ns)

        # Call the function
        if tc_out["exceptions"]:
            with pytest.raises(Exception) as e:
                args.func(args)
            for expected in tc_out["exceptions"]:
                assert expected in str(e.value)
        else:
            args.func(args)

        # Check if the expected messages are in the log
        if tc_out["warnings"]:
            for expected in tc_out["warnings"]:
                assert expected in caplog.text

        # If a log file was supposed to exist, check the content
        if args.logfile:
            if os.path.isfile(args.logfile):
                with open(args.logfile, "r") as log:
                    logged = log.read()
                    if tc_out["warnings"]:
                        for expected in tc_out["warnings"]:
                            assert expected in logged
                    if tc_out["exceptions"]:
                        for expected in tc_out["exceptions"]:
                            assert expected in logged
            else:
                if tc_out["warnings"] or tc_out["exceptions"]:
                    with capsys.disabled():
                        print(tc)
                        print("Expected to have a logfile:\n" + args.logfile)
                    # Fail
                    assert 0

        # Clear the captured log and output so far
        caplog.clear()