Ejemplo n.º 1
0
def test_previous():
    """
    Previous works
    """
    os.environ["TMC_TESTING"] = "1"

    _, _, ex = run_command("previous")
    assert ex is None

    _, _, ex = run_command("previous")
    assert ex is not None
Ejemplo n.º 2
0
def test_previous():
    """
    Previous works
    """
    os.environ["TMC_TESTING"] = "1"

    _, _, ex = run_command("previous")
    assert ex is None

    _, _, ex = run_command("previous")
    assert ex is not None
Ejemplo n.º 3
0
def test_reset():
    """
    Database resetting works
    """
    import tmc.ui.prompt
    tmc.ui.prompt.input = lambda _: "y"
    stdout, _, _ = run_command("reset")
    assert "Database resetted." in stdout
    tmc.ui.prompt.input = lambda _: "n"
    stdout, _, _ = run_command("reset")
    assert "Database resetted." not in stdout
Ejemplo n.º 4
0
def test_reset():
    """
    Database resetting works
    """
    import tmc.ui.prompt
    tmc.ui.prompt.input = lambda _: "y"
    stdout, _, _ = run_command("reset")
    assert "Database resetted." in stdout
    tmc.ui.prompt.input = lambda _: "n"
    stdout, _, _ = run_command("reset")
    assert "Database resetted." not in stdout
Ejemplo n.º 5
0
def test_configure():
    """
    Configuring works
    """
    _, _, ex = run_command([
        "configure", "-u", username, "-p", password, "-s", server_uri, "-i",
        course_id, "--auto"
    ])
    assert ex is None
Ejemplo n.º 6
0
def test_configure():
    """
    Configuring works
    """
    _, _, ex = run_command(
        ["configure", "-u", username, "-p", password, "-s", server_uri,
         "-i", course_id, "--auto"]
    )
    assert ex is None
Ejemplo n.º 7
0
def test_download_single():
    """
    Downloading works
    """
    _, _, ex = run_command(["download", "-f", "-i", exercise_id])
    assert ex is None

    from tmc.models import Exercise

    assert Exercise.get_selected().is_downloaded == True
Ejemplo n.º 8
0
def test_download_single():
    """
    Downloading works
    """
    _, _, ex = run_command(["download", "-f", "-i", exercise_id])
    assert ex is None

    from tmc.models import Exercise

    assert Exercise.get_selected().is_downloaded == True
Ejemplo n.º 9
0
def test_test_fail():
    """
    Testing can fail
    """
    from tmc.models import Exercise

    fpath = path.join(Exercise.get_selected().path(), "src", "Nimi.java")
    with open(fpath, "w") as f:
        f.write(fail_file)

    os.environ["TMC_TESTING"] = "1"
    wasexit = False
    stdout, stderr, exception = run_command("test")
    if type(exception) == TMCExit:
        wasexit = True
    assert wasexit == True
    assert "Results:" in stdout
    assert "\033[31m" in stderr and "\033[0m" in stderr
Ejemplo n.º 10
0
def test_test_fail():
    """
    Testing can fail
    """
    from tmc.models import Exercise

    fpath = path.join(Exercise.get_selected().path(), "src", "Nimi.java")
    with open(fpath, "w") as f:
        f.write(fail_file)

    os.environ["TMC_TESTING"] = "1"
    wasexit = False
    stdout, stderr, exception = run_command("test")
    if type(exception) == TMCExit:
        wasexit = True
    assert wasexit == True
    assert "Results:" in stdout
    assert "\033[31m" in stderr and "\033[0m" in stderr
Ejemplo n.º 11
0
def test_submit_fail():
    """
    Submitted exercise can fail
    """
    from tmc.models import Exercise

    fpath = path.join(Exercise.get_selected().path(), "src", "Nimi.java")
    with open(fpath, "w") as f:
        f.write(fail_file)

    os.environ["TMC_TESTING"] = "1"
    wasexit = False
    stdout, stderr, exception = run_command("submit")
    if type(exception) == TMCExit:
        wasexit = True
    assert wasexit == True
    assert "Results:" in stdout
    uri = os.getenv("TMC_URI", server_uri)
    assert "Submission URL: " + uri + "submissions/" in stdout
    assert "Pastebin: " + uri + "paste/" not in stdout
    assert "Requested a review" not in stdout
    assert "\033[31m" in stderr and "\033[0m" in stderr
Ejemplo n.º 12
0
def test_submit_fail():
    """
    Submitted exercise can fail
    """
    from tmc.models import Exercise

    fpath = path.join(Exercise.get_selected().path(), "src", "Nimi.java")
    with open(fpath, "w") as f:
        f.write(fail_file)

    os.environ["TMC_TESTING"] = "1"
    wasexit = False
    stdout, stderr, exception = run_command("submit")
    if type(exception) == TMCExit:
        wasexit = True
    assert wasexit == True
    assert "Results:" in stdout
    uri = os.getenv("TMC_URI", server_uri)
    assert "Submission URL: " + uri + "submissions/" in stdout
    assert "Pastebin: " + uri + "paste/" not in stdout
    assert "Requested a review" not in stdout
    assert "\033[31m" in stderr and "\033[0m" in stderr
Ejemplo n.º 13
0
def test_submit_success():
    """
    Submitted exercise can succeed
    """
    from tmc.models import Exercise

    fpath = path.join(Exercise.get_selected().path(), "src", "Nimi.java")
    with open(fpath, "w") as f:
        f.write(success_file)

    os.environ["TMC_TESTING"] = "1"
    wasexit = False
    stdout, stderr, exception = run_command(["submit", "-p", "-r"])
    if type(exception) == TMCExit:
        wasexit = True
    assert wasexit == False
    assert "Results:" in stdout
    assert "Points [1]" in stdout
    assert "Requested a review" in stdout
    uri = os.getenv("TMC_URI", server_uri)
    assert "Submission URL: " + uri + "submissions/" in stdout
    assert "Pastebin: " + uri + "paste/" in stdout

    assert len(stderr) == 0
Ejemplo n.º 14
0
def test_submit_success():
    """
    Submitted exercise can succeed
    """
    from tmc.models import Exercise

    fpath = path.join(Exercise.get_selected().path(), "src", "Nimi.java")
    with open(fpath, "w") as f:
        f.write(success_file)

    os.environ["TMC_TESTING"] = "1"
    wasexit = False
    stdout, stderr, exception = run_command(["submit", "-p", "-r"])
    if type(exception) == TMCExit:
        wasexit = True
    assert wasexit == False
    assert "Results:" in stdout
    assert "Points [1]" in stdout
    assert "Requested a review" in stdout
    uri = os.getenv("TMC_URI", server_uri)
    assert "Submission URL: " + uri + "submissions/" in stdout
    assert "Pastebin: " + uri + "paste/" in stdout

    assert len(stderr) == 0
Ejemplo n.º 15
0
def test_version():
    """
    Prints the version correctly
    """
    stdout, _, _ = run_command("version")
    assert "tmc.py version {}".format(version) in stdout
Ejemplo n.º 16
0
def test_select():
    """
    Selecting works
    """
    _, _, ex = run_command(["select", "-i", exercise_id])
    assert ex is None
Ejemplo n.º 17
0
def test_next():
    """
    Next works
    """
    _, _, ex = run_command("next")
    assert ex is None
Ejemplo n.º 18
0
def test_next():
    """
    Next works
    """
    _, _, ex = run_command("next")
    assert ex is None
Ejemplo n.º 19
0
def test_select():
    """
    Selecting works
    """
    _, _, ex = run_command(["select", "-i", exercise_id])
    assert ex is None
Ejemplo n.º 20
0
def test_version():
    """
    Prints the version correctly
    """
    stdout, _, _ = run_command("version")
    assert "tmc.py version {}".format(version) in stdout