def test_ignores_non_digits(monkeypatch, capsys):
    monkeypatch.setattr("sys.stdin", StringIO("4257a123"))
    s = Shakespeare("Foo. Juliet, a test. Romeo, a test.")
    s.run_event("[Enter Romeo and Juliet]")
    s.run_sentence("Listen to your heart!", "Juliet")
    assert s.state.character_by_name("Romeo").value == 4257
    captured = capsys.readouterr()
    assert captured.out == ""
    assert captured.err == ""
def test_interactive_style(monkeypatch, capsys):
    monkeypatch.setattr("sys.stdin", StringIO("4257\n3211"))
    s = Shakespeare("Foo. Juliet, a test. Romeo, a test.",
                    input_style="interactive")
    s.run_event("[Enter Romeo and Juliet]")

    s.run_sentence("Listen to your heart!", "Juliet")
    assert s.state.character_by_name("Romeo").value == 4257
    captured = capsys.readouterr()
    assert captured.out == "Taking input number: "
    assert captured.err == ""
Beispiel #3
0
def test_errors_on_exit_before_entrance():
    s = Shakespeare(
        "Foo. Juliet, a test. Romeo, a test. The Ghost, a test. Demetrius, a test."
    )
    assert_off_stage(s, ["Juliet", "Romeo", "The Ghost", "Demetrius"])

    with pytest.raises(ShakespeareRuntimeError) as exc:
        s.run_event("[Exit Juliet]")
    assert "not on stage" in str(exc.value).lower()
    assert ">>[Exit Juliet]<<" in str(exc.value)
    assert exc.value.interpreter == s
    assert_off_stage(s, ["Juliet", "Romeo", "The Ghost", "Demetrius"])
def test_errors_on_eof(monkeypatch, capsys):
    monkeypatch.setattr("sys.stdin", StringIO(""))
    s = Shakespeare("Foo. Juliet, a test. Romeo, a test.")
    s.run_event("[Enter Romeo and Juliet]")
    with pytest.raises(ShakespeareRuntimeError) as exc:
        s.run_sentence("Listen to your heart!", "Juliet")
    assert "end of file" in str(exc.value).lower()
    assert ">>Listen to your heart!<<" in str(exc.value)
    assert exc.value.interpreter == s
    assert s.state.character_by_name("Romeo").value == 0
    captured = capsys.readouterr()
    assert captured.out == ""
    assert captured.err == ""
Beispiel #5
0
def test_exeunt_four_explicit():
    s = Shakespeare(
        "Foo. Juliet, a test. Romeo, a test. The Ghost, a test. Demetrius, a test."
    )
    assert_off_stage(s, ["Juliet", "Romeo", "The Ghost", "Demetrius"])

    s.run_event("[Enter Demetrius, The Ghost, Juliet and Romeo]")
    assert_on_stage(s, ["Demetrius", "The Ghost", "Juliet", "Romeo"])
    assert_off_stage(s, [])

    s.run_event("[Exeunt Demetrius, The Ghost, Juliet and Romeo]")
    assert_on_stage(s, [])
    assert_off_stage(s, ["Demetrius", "Romeo", "The Ghost", "Juliet"])
Beispiel #6
0
def test_complex_expressions():
    s = Shakespeare("Foo. Juliet, a test. Romeo, a test.")
    s.run_event("[Enter Romeo and Juliet]")
    # (2 * ((4 + 2)^3) * (2 + 4)) % (1 + (2 * (2 + 1))) = 2
    first_expression = """
        the remainder of the quotient between
            twice
                the product of
                    the cube of
                        the sum of
                            my big chihuahua
                            and
                            my big big chihuahua
                    and
                    the sum of
                        my big chihuahua
                        and
                        my big big chihuahua
            and
            the sum of
                my chihuahua
                and
                twice
                    the sum of
                        my big chihuahua
                        and
                        my chihuahua
    """
    assert s.evaluate_expression(first_expression, "Juliet") == 2
    # (8! - (16^3 - 1)) % (16 - (2 + 1)) = 7
    second_expression = """
        the remainder of the quotient between
            the difference between
                the factorial of
                    my big big big chihuahua
                and
                the difference between
                    the cube of
                        my big big big big chihuahua
                    and
                    my chihuahua
            and
            the difference between
                my big big big big chihuahua
                and
                the sum of
                    my big chihuahua
                    and
                    my chihuahua
    """
    assert s.evaluate_expression(second_expression, "Juliet") == 7
def test_consumes_trailing_newline(monkeypatch, capsys):
    monkeypatch.setattr("sys.stdin", StringIO("4257\na"))
    s = Shakespeare("Foo. Juliet, a test. Romeo, a test.")
    s.run_event("[Enter Romeo and Juliet]")
    s.run_sentence("Listen to your heart!", "Juliet")
    assert s.state.character_by_name("Romeo").value == 4257
    assert input() == "a"
    captured = capsys.readouterr()
    assert captured.out == ""
    assert captured.err == ""

    # Make sure there isn't a '\n' still living in the buffer
    s.run_sentence("Open your mind!", "Juliet")
    assert s.state.character_by_name("Romeo").value == -1
Beispiel #8
0
def test_assign_character(capsys):
    s = Shakespeare("Foo. Juliet, a test. Romeo, a test.")
    s.run_event("[Enter Romeo and Juliet]")

    assert s.state.character_by_name("Romeo").value == 0
    s.run_sentence("You are as good as a furry animal!", "Juliet")
    assert s.state.character_by_name("Romeo").value == 2

    s.state.character_by_name("Romeo").value = 0
    s.run_sentence("You are a pig!", "Juliet")
    assert s.state.character_by_name("Romeo").value == -1
    captured = capsys.readouterr()
    assert captured.out == ""
    assert captured.err == ""
def test_eof_character_code(monkeypatch, capsys):
    monkeypatch.setattr("sys.stdin", StringIO("&"))
    s = Shakespeare("Foo. Juliet, a test. Romeo, a test.")
    s.run_event("[Enter Romeo and Juliet]")

    s.run_sentence("Open your mind!", "Juliet")
    assert s.state.character_by_name("Romeo").value == 38

    s.run_sentence("Open your mind!", "Juliet")
    assert s.state.character_by_name("Romeo").value == -1

    captured = capsys.readouterr()
    assert captured.out == ""
    assert captured.err == ""
Beispiel #10
0
def test_goto_without_opposite_character(capsys):
    s = Shakespeare(SAMPLE_PLAY)

    assert s.current_position == 0
    s.step_forward()
    assert s.current_position == 1
    s.run_event("[Exit Romeo]")
    s.run_sentence("Let us proceed to scene II.", "Juliet")
    assert s.current_position == 2
    s.run_event("[Enter Romeo and Macbeth]")
    s.run_sentence("Let us proceed to scene I.", "Juliet")
    assert s.current_position == 0

    captured = capsys.readouterr()
    assert captured.out == ""
    assert captured.err == ""
Beispiel #11
0
def test_errors_on_partial_duplicate_entrance():
    s = Shakespeare(
        "Foo. Juliet, a test. Romeo, a test. The Ghost, a test. Demetrius, a test."
    )
    assert_off_stage(s, ["Juliet", "Romeo", "The Ghost", "Demetrius"])

    s.run_event("[Enter Juliet]")
    assert_on_stage(s, ["Juliet"])
    assert_off_stage(s, ["Romeo", "The Ghost", "Demetrius"])

    with pytest.raises(ShakespeareRuntimeError) as exc:
        s.run_event("[Enter The Ghost and Juliet]")
    assert "already on stage" in str(exc.value).lower()
    assert ">>[Enter The Ghost and Juliet]<<" in str(exc.value)
    assert exc.value.interpreter == s
    assert_on_stage(s, ["Juliet"])
    assert_off_stage(s, ["Romeo", "The Ghost", "Demetrius"])
Beispiel #12
0
def test_errors_on_pop_from_empty():
    s = Shakespeare("Foo. Juliet, a test. Romeo, a test.")
    s.run_event("[Enter Romeo and Juliet]")

    c = s.state.character_by_name("Juliet")
    assert c.stack == []
    assert c.value == 0

    with pytest.raises(ShakespeareRuntimeError) as exc:
        s.run_sentence("Recall thy terrible memory of thy imminent death.",
                       "Romeo")
    assert "empty stack" in str(exc.value).lower()
    assert ">>Recall thy terrible memory of thy imminent death.<<" in str(
        exc.value)
    assert exc.value.interpreter == s

    assert c.stack == []
    assert c.value == 0
Beispiel #13
0
def test_twice():
    s = Shakespeare("Foo. Juliet, a test. Romeo, a test.")
    s.run_event("[Enter Romeo and Juliet]")
    s.state.character_by_name("Romeo").value = 4
    assert s.evaluate_expression("twice yourself", "Juliet") == 8
    assert s.evaluate_expression("twice my big big chihuahua", "Juliet") == 8
    s.state.character_by_name("Romeo").value = 1
    assert s.evaluate_expression("twice thyself", "Juliet") == 2
    assert s.evaluate_expression("twice my chihuahua", "Juliet") == 2
    s.state.character_by_name("Romeo").value = 0
    assert s.evaluate_expression("twice thyself", "Juliet") == 0
    assert s.evaluate_expression("twice nothing", "Juliet") == 0
    s.state.character_by_name("Romeo").value = -1
    assert s.evaluate_expression("twice thyself", "Juliet") == -2
    assert s.evaluate_expression("twice thy devil", "Juliet") == -2
    s.state.character_by_name("Romeo").value = -4
    assert s.evaluate_expression("twice thyself", "Juliet") == -8
    assert s.evaluate_expression("twice thy foul stupid devil", "Juliet") == -8
Beispiel #14
0
def test_square_root_of():
    s = Shakespeare("Foo. Juliet, a test. Romeo, a test.")
    s.run_event("[Enter Romeo and Juliet]")
    s.state.character_by_name("Romeo").value = 16
    assert s.evaluate_expression("the square root of yourself", "Juliet") == 4
    assert (
        s.evaluate_expression(
            "the square root of my big big big big chihuahua", "Juliet"
        )
        == 4
    )
    s.state.character_by_name("Romeo").value = 18
    assert s.evaluate_expression("the square root of yourself", "Juliet") == 4
    s.state.character_by_name("Romeo").value = 41
    assert s.evaluate_expression("the square root of yourself", "Juliet") == 6
    s.state.character_by_name("Romeo").value = 1
    assert s.evaluate_expression("the square root of thyself", "Juliet") == 1
    assert s.evaluate_expression("the square root of my chihuahua", "Juliet") == 1
    s.state.character_by_name("Romeo").value = 0
    assert s.evaluate_expression("the square root of thyself", "Juliet") == 0
    assert s.evaluate_expression("the square root of nothing", "Juliet") == 0
    s.state.character_by_name("Romeo").value = -1
    with pytest.raises(ShakespeareRuntimeError) as exc:
        s.evaluate_expression("the square root of thyself", "Juliet")
    assert "negative" in str(exc.value).lower()
    assert ">>the square root of thyself<<" in str(exc.value)
    assert exc.value.interpreter == s
    with pytest.raises(ShakespeareRuntimeError) as exc:
        s.evaluate_expression("the square root of thy devil", "Juliet")
    assert "negative" in str(exc.value).lower()
    assert ">>the square root of thy devil<<" in str(exc.value)
    assert exc.value.interpreter == s
    s.state.character_by_name("Romeo").value = -4
    with pytest.raises(ShakespeareRuntimeError) as exc:
        s.evaluate_expression("the square root of thyself", "Juliet")
    assert "negative" in str(exc.value).lower()
    assert ">>the square root of thyself<<" in str(exc.value)
    assert exc.value.interpreter == s
    with pytest.raises(ShakespeareRuntimeError) as exc:
        s.evaluate_expression("the square root of thy foul stupid devil", "Juliet")
    assert "negative" in str(exc.value).lower()
    assert ">>the square root of thy foul stupid devil<<" in str(exc.value)
    assert exc.value.interpreter == s
Beispiel #15
0
def test_push():
    s = Shakespeare("Foo. Juliet, a test. Romeo, a test.")
    s.run_event("[Enter Romeo and Juliet]")

    c = s.state.character_by_name("Juliet")
    assert c.stack == []
    assert c.value == 0

    s.run_sentence("Remember a furry animal.", "Romeo")
    assert c.stack == [2]
    assert c.value == 0

    s.run_sentence("Remember a furry furry animal.", "Romeo")
    assert c.stack == [2, 4]
    assert c.value == 0

    s.run_sentence("Remember a furry furry furry animal.", "Romeo")
    assert c.stack == [2, 4, 8]
    assert c.value == 0
Beispiel #16
0
def test_cube_of():
    s = Shakespeare("Foo. Juliet, a test. Romeo, a test.")
    s.run_event("[Enter Romeo and Juliet]")
    s.state.character_by_name("Romeo").value = 4
    assert s.evaluate_expression("the cube of yourself", "Juliet") == 64
    assert (
        s.evaluate_expression("the cube of my golden golden chihuahua", "Juliet") == 64
    )
    s.state.character_by_name("Romeo").value = 1
    assert s.evaluate_expression("the cube of thyself", "Juliet") == 1
    assert s.evaluate_expression("the cube of my chihuahua", "Juliet") == 1
    s.state.character_by_name("Romeo").value = 0
    assert s.evaluate_expression("the cube of thyself", "Juliet") == 0
    assert s.evaluate_expression("the cube of nothing", "Juliet") == 0
    s.state.character_by_name("Romeo").value = -1
    assert s.evaluate_expression("the cube of thyself", "Juliet") == -1
    assert s.evaluate_expression("the cube of thy devil", "Juliet") == -1
    s.state.character_by_name("Romeo").value = -4
    assert s.evaluate_expression("the cube of thyself", "Juliet") == -64
    assert s.evaluate_expression("the cube of thy foul stupid devil", "Juliet") == -64
Beispiel #17
0
def test_outputs_numbers(capsys):
    s = Shakespeare("Foo. Juliet, a test. Romeo, a test.")
    s.run_event("[Enter Romeo and Juliet]")

    s.state.character_by_name("Romeo").value = 4100
    s.run_sentence("Open your heart!", "Juliet")
    captured = capsys.readouterr()
    assert captured.out == "4100"
    assert captured.err == ""

    s.state.character_by_name("Romeo").value = -5
    s.run_sentence("Open your heart!", "Juliet")
    captured = capsys.readouterr()
    assert captured.out == "-5"
    assert captured.err == ""

    s.state.character_by_name("Romeo").value = 9
    s.run_sentence("Open your heart!", "Juliet")
    captured = capsys.readouterr()
    assert captured.out == "9"
    assert captured.err == ""
def test_errors_on_invalid_code(capsys):
    s = Shakespeare("Foo. Juliet, a test. Romeo, a test.")
    s.run_event("[Enter Romeo and Juliet]")

    s.state.character_by_name("Romeo").value = 100000000
    with pytest.raises(ShakespeareRuntimeError) as exc:
        s.run_sentence("Speak your mind!", "Juliet")
    assert "invalid character code" in str(exc.value).lower()
    assert ">>Speak your mind!<<" in str(exc.value)
    assert exc.value.interpreter == s

    s.state.character_by_name("Romeo").value = -1
    with pytest.raises(ShakespeareRuntimeError) as exc:
        s.run_sentence("Speak your mind!", "Juliet")
    assert "invalid character code" in str(exc.value).lower()
    assert ">>Speak your mind!<<" in str(exc.value)
    assert exc.value.interpreter == s

    captured = capsys.readouterr()
    assert captured.out == ""
    assert captured.err == ""
def test_unicode(monkeypatch, capsys):
    monkeypatch.setattr("sys.stdin", StringIO("ʘɥӜआઔඦᢶᨆᵇḤ"))
    s = Shakespeare("Foo. Juliet, a test. Romeo, a test.")
    s.run_event("[Enter Romeo and Juliet]")

    s.run_sentence("Open your mind!", "Juliet")
    assert s.state.character_by_name("Romeo").value == 664

    s.run_sentence("Open your mind!", "Juliet")
    assert s.state.character_by_name("Romeo").value == 613

    s.run_sentence("Open your mind!", "Juliet")
    assert s.state.character_by_name("Romeo").value == 1244

    s.run_sentence("Open your mind!", "Juliet")
    assert s.state.character_by_name("Romeo").value == 2310

    s.run_sentence("Open your mind!", "Juliet")
    assert s.state.character_by_name("Romeo").value == 2708

    s.run_sentence("Open your mind!", "Juliet")
    assert s.state.character_by_name("Romeo").value == 3494

    s.run_sentence("Open your mind!", "Juliet")
    assert s.state.character_by_name("Romeo").value == 6326

    s.run_sentence("Open your mind!", "Juliet")
    assert s.state.character_by_name("Romeo").value == 6662

    s.run_sentence("Open your mind!", "Juliet")
    assert s.state.character_by_name("Romeo").value == 7495

    s.run_sentence("Open your mind!", "Juliet")
    assert s.state.character_by_name("Romeo").value == 7716

    captured = capsys.readouterr()
    assert captured.out == ""
    assert captured.err == ""
def test_conditional(monkeypatch, capsys):
    monkeypatch.setattr("sys.stdin", StringIO("ab"))
    s = Shakespeare("Foo. Juliet, a test. Romeo, a test.")
    s.run_event("[Enter Romeo and Juliet]")

    s.state.global_boolean = False
    s.run_sentence("If so, open your mind!", "Juliet")
    assert s.state.character_by_name("Romeo").value == 0

    s.state.global_boolean = True
    s.run_sentence("If not, open your mind!", "Juliet")
    assert s.state.character_by_name("Romeo").value == 0

    s.state.global_boolean = True
    s.run_sentence("If so, open your mind!", "Juliet")
    assert s.state.character_by_name("Romeo").value == 97

    s.state.global_boolean = False
    s.run_sentence("If not, open your mind!", "Juliet")
    assert s.state.character_by_name("Romeo").value == 98

    captured = capsys.readouterr()
    assert captured.out == ""
    assert captured.err == ""
Beispiel #21
0
def test_pop():
    s = Shakespeare("Foo. Juliet, a test. Romeo, a test.")
    s.run_event("[Enter Romeo and Juliet]")

    c = s.state.character_by_name("Juliet")
    assert c.stack == []
    assert c.value == 0

    c.stack = [234, 123, 678]

    s.run_sentence("Recall thy terrible memory of thy imminent death.",
                   "Romeo")
    assert c.stack == [234, 123]
    assert c.value == 678

    s.run_sentence("Recall thy terrible memory of thy imminent death.",
                   "Romeo")
    assert c.stack == [234]
    assert c.value == 123

    s.run_sentence("Recall thy terrible memory of thy imminent death.",
                   "Romeo")
    assert c.stack == []
    assert c.value == 234
def test_unicode(capsys):
    s = Shakespeare("Foo. Juliet, a test. Romeo, a test. Act I: One. Scene I: One.")
    s.run_event("[Enter Romeo and Juliet]")

    s.state.character_by_name("Romeo").value = 664
    s.run_sentence("Speak your mind!", "Juliet")
    captured = capsys.readouterr()
    assert captured.out == "ʘ"
    assert captured.err == ""

    s.state.character_by_name("Romeo").value = 613
    s.run_sentence("Speak your mind!", "Juliet")
    captured = capsys.readouterr()
    assert captured.out == "ɥ"
    assert captured.err == ""

    s.state.character_by_name("Romeo").value = 1244
    s.run_sentence("Speak your mind!", "Juliet")
    captured = capsys.readouterr()
    assert captured.out == "Ӝ"
    assert captured.err == ""

    s.state.character_by_name("Romeo").value = 2310
    s.run_sentence("Speak your mind!", "Juliet")
    captured = capsys.readouterr()
    assert captured.out == "आ"
    assert captured.err == ""

    s.state.character_by_name("Romeo").value = 2708
    s.run_sentence("Speak your mind!", "Juliet")
    captured = capsys.readouterr()
    assert captured.out == "ઔ"
    assert captured.err == ""

    s.state.character_by_name("Romeo").value = 3494
    s.run_sentence("Speak your mind!", "Juliet")
    captured = capsys.readouterr()
    assert captured.out == "ඦ"
    assert captured.err == ""

    s.state.character_by_name("Romeo").value = 6326
    s.run_sentence("Speak your mind!", "Juliet")
    captured = capsys.readouterr()
    assert captured.out == "ᢶ"
    assert captured.err == ""

    s.state.character_by_name("Romeo").value = 6662
    s.run_sentence("Speak your mind!", "Juliet")
    captured = capsys.readouterr()
    assert captured.out == "ᨆ"
    assert captured.err == ""

    s.state.character_by_name("Romeo").value = 7495
    s.run_sentence("Speak your mind!", "Juliet")
    captured = capsys.readouterr()
    assert captured.out == "ᵇ"
    assert captured.err == ""

    s.state.character_by_name("Romeo").value = 7716
    s.run_sentence("Speak your mind!", "Juliet")
    captured = capsys.readouterr()
    assert captured.out == "Ḥ"
    assert captured.err == ""
Beispiel #23
0
def test_difference_between():
    s = Shakespeare("Foo. Juliet, a test. Romeo, a test.")
    s.run_event("[Enter Romeo and Juliet]")
    s.state.character_by_name("Romeo").value = 4
    assert (
        s.evaluate_expression("the difference between yourself and nothing", "Juliet")
        == 4
    )
    assert (
        s.evaluate_expression(
            "the difference between yourself and my chihuahua", "Juliet"
        )
        == 3
    )
    assert (
        s.evaluate_expression(
            "the difference between yourself and my codpiece", "Juliet"
        )
        == 5
    )
    assert (
        s.evaluate_expression(
            "the difference between yourself and my big big chihuahua", "Juliet"
        )
        == 0
    )
    s.state.character_by_name("Romeo").value = 1
    assert (
        s.evaluate_expression("the difference between yourself and nothing", "Juliet")
        == 1
    )
    assert (
        s.evaluate_expression(
            "the difference between yourself and my chihuahua", "Juliet"
        )
        == 0
    )
    assert (
        s.evaluate_expression(
            "the difference between yourself and my codpiece", "Juliet"
        )
        == 2
    )
    s.state.character_by_name("Romeo").value = 0
    assert (
        s.evaluate_expression("the difference between thyself and nothing", "Juliet")
        == 0
    )
    assert (
        s.evaluate_expression(
            "the difference between yourself and my chihuahua", "Juliet"
        )
        == -1
    )
    assert (
        s.evaluate_expression(
            "the difference between yourself and my codpiece", "Juliet"
        )
        == 1
    )
    s.state.character_by_name("Romeo").value = -1
    assert (
        s.evaluate_expression("the difference between yourself and nothing", "Juliet")
        == -1
    )
    assert (
        s.evaluate_expression(
            "the difference between yourself and my chihuahua", "Juliet"
        )
        == -2
    )
    assert (
        s.evaluate_expression(
            "the difference between yourself and my codpiece", "Juliet"
        )
        == 0
    )
    s.state.character_by_name("Romeo").value = -4
    assert (
        s.evaluate_expression("the difference between yourself and nothing", "Juliet")
        == -4
    )
    assert (
        s.evaluate_expression(
            "the difference between yourself and my chihuahua", "Juliet"
        )
        == -5
    )
    assert (
        s.evaluate_expression(
            "the difference between yourself and my codpiece", "Juliet"
        )
        == -3
    )
    assert (
        s.evaluate_expression(
            "the difference between thyself and thy foul stupid devil", "Juliet"
        )
        == 0
    )
Beispiel #24
0
def test_complex_shuffle():
    s = Shakespeare(
        "Foo. Juliet, a test. Romeo, a test. The Ghost, a test. Demetrius, a test."
    )
    assert_off_stage(s, ["Juliet", "Romeo", "The Ghost", "Demetrius"])

    s.run_event("[Enter Demetrius and Juliet]")
    assert_on_stage(s, ["Demetrius", "Juliet"])
    assert_off_stage(s, ["The Ghost", "Romeo"])

    s.run_event("[Exit Juliet]")
    assert_on_stage(s, ["Demetrius"])
    assert_off_stage(s, ["The Ghost", "Romeo", "Juliet"])

    s.run_event("[Enter Romeo]")
    assert_on_stage(s, ["Demetrius", "Romeo"])
    assert_off_stage(s, ["The Ghost", "Juliet"])

    s.run_event("[Enter The Ghost]")
    assert_on_stage(s, ["Demetrius", "Romeo", "The Ghost"])
    assert_off_stage(s, ["Juliet"])

    s.run_event("[Exeunt Demetrius and The Ghost]")
    assert_on_stage(s, ["Romeo"])
    assert_off_stage(s, ["Juliet", "Demetrius", "The Ghost"])

    s.run_event("[Enter Juliet]")
    assert_on_stage(s, ["Romeo", "Juliet"])
    assert_off_stage(s, ["Demetrius", "The Ghost"])

    s.run_event("[Exeunt]")
    assert_on_stage(s, [])
    assert_off_stage(s, ["Demetrius", "The Ghost", "Romeo", "Juliet"])
Beispiel #25
0
def test_remainder():
    s = Shakespeare("Foo. Juliet, a test. Romeo, a test.")
    s.run_event("[Enter Romeo and Juliet]")
    s.state.character_by_name("Romeo").value = 12
    assert (
        s.evaluate_expression(
            "the remainder of the quotient between yourself and my chihuahua", "Juliet"
        )
        == 0
    )
    assert (
        s.evaluate_expression(
            "the remainder of the quotient between yourself and my big chihuahua",
            "Juliet",
        )
        == 0
    )
    assert (
        s.evaluate_expression(
            "the remainder of the quotient between yourself and my big big chihuahua",
            "Juliet",
        )
        == 0
    )
    assert (
        s.evaluate_expression(
            "the remainder of the quotient between yourself and my codpiece", "Juliet"
        )
        == 0
    )
    assert (
        s.evaluate_expression(
            "the remainder of the quotient between yourself and my foul codpiece",
            "Juliet",
        )
        == 0
    )
    assert (
        s.evaluate_expression(
            "the remainder of the quotient between yourself and my foul rotten codpiece",
            "Juliet",
        )
        == 0
    )
    assert (
        s.evaluate_expression(
            "the remainder of the quotient between yourself and yourself", "Juliet"
        )
        == 0
    )
    assert (
        s.evaluate_expression(
            "the remainder of the quotient between my big big chihuahua and yourself",
            "Juliet",
        )
        == 4
    )
    assert (
        s.evaluate_expression(
            "the remainder of the quotient between my foul rotten codpiece and yourself",
            "Juliet",
        )
        == -4
    )
    s.state.character_by_name("Romeo").value = 23
    assert (
        s.evaluate_expression(
            "the remainder of the quotient between yourself and my big big big chihuahua",
            "Juliet",
        )
        == 7
    )
    assert (
        s.evaluate_expression(
            "the remainder of the quotient between yourself and my evil foul rotten codpiece",
            "Juliet",
        )
        == 7
    )

    with pytest.raises(ShakespeareRuntimeError) as exc:
        s.evaluate_expression(
            "the remainder of the quotient between yourself and nothing", "Juliet"
        )
    assert "zero" in str(exc.value).lower()
    assert ">>the remainder of the quotient between yourself and nothing<<" in str(
        exc.value
    )
    assert exc.value.interpreter == s