Exemplo n.º 1
0
def test_count_regex_from_contents():
    """Check that counting regex in a string works correctly."""
    value = "\\begin{document} hello! \\end{document}"
    count, _ = fragments.count_entities(r"\\begin(.*?)\\end",
                                        fragments.count_specified_regex,
                                        contents=value)
    assert count == 1
    count, _ = fragments.count_entities(r"planet",
                                        fragments.count_specified_regex,
                                        contents=value)
    assert count == 0
    count, _ = fragments.count_entities(r"invalid[^]",
                                        fragments.count_specified_regex,
                                        contents=value)
    assert count == -1
Exemplo n.º 2
0
def test_count_entities_from_contents():
    """Check that counting fragments in a string works correctly."""
    value = "/* hello world */"
    count, _ = fragments.count_entities("hello",
                                        fragments.count_specified_fragment,
                                        contents=value)
    assert count == 1
    count, _ = fragments.count_entities("world",
                                        fragments.count_specified_fragment,
                                        contents=value)
    assert count == 1
    count, _ = fragments.count_entities("planet",
                                        fragments.count_specified_fragment,
                                        contents=value)
    assert count == 0
Exemplo n.º 3
0
def test_count_entities_from_contents_mimic_command_no_output():
    """Check that counting fragments in a string works correctly if from an error-ed command."""
    # this is a signal to indicate that a command error-ed and thus the output
    # of the command is actually "", meaning it did not produce output
    value = "Command_No_Output"
    # none of the calls to count_entities should be able to count anything
    count, _ = fragments.count_entities("hello",
                                        fragments.count_specified_fragment,
                                        contents=value)
    assert count == 0
    count, _ = fragments.count_entities("world",
                                        fragments.count_specified_fragment,
                                        contents=value)
    assert count == 0
    count, _ = fragments.count_entities("planet",
                                        fragments.count_specified_fragment,
                                        contents=value)
    assert count == 0
Exemplo n.º 4
0
def test_count_regex_from_file(tmpdir):
    """Check that counting regex in a file works correctly."""
    hello_file = tmpdir.mkdir("subdirectory").join("Hello.java")
    hello_file.write("\\begin{document} hello! \\end{document}")
    assert hello_file.read() == "\\begin{document} hello! \\end{document}"
    assert len(tmpdir.listdir()) == 1
    directory = tmpdir.dirname + "/" + tmpdir.basename + "/" + "subdirectory"
    hello_file = "Hello.java"
    count, _ = fragments.count_entities(r"\\begin(.*?)\\end",
                                        fragments.count_specified_regex,
                                        hello_file, directory)
    assert count == 1
    count, _ = fragments.count_entities(r"planet",
                                        fragments.count_specified_regex,
                                        hello_file, directory, "")
    assert count == 0
    count, _ = fragments.count_entities(r"invalid[^]",
                                        fragments.count_specified_regex,
                                        hello_file, directory, "")
    assert count == -1
Exemplo n.º 5
0
def test_count_entities_from_file(tmpdir):
    """Check that counting fragments in a file works correctly."""
    hello_file = tmpdir.mkdir("subdirectory").join("Hello.java")
    hello_file.write("/* hello world */")
    assert hello_file.read() == "/* hello world */"
    assert len(tmpdir.listdir()) == 1
    directory = tmpdir.dirname + "/" + tmpdir.basename + "/" + "subdirectory"
    hello_file = "Hello.java"
    count, _ = fragments.count_entities("hello",
                                        fragments.count_specified_fragment,
                                        hello_file, directory, "")
    assert count == 1
    count, _ = fragments.count_entities("world",
                                        fragments.count_specified_fragment,
                                        hello_file, directory, "")
    assert count == 1
    count, _ = fragments.count_entities("planet",
                                        fragments.count_specified_fragment,
                                        hello_file, directory, "")
    assert count == 0