Exemple #1
0
def test_find_in_file_with_comment(match_class):
    with tempfile.NamedTemporaryFile("w+") as handler:
        handler.write('''# Raincoat: pypi package: BLA==1.2.3 path: yo/yeah.py element: foo  # noqa''')  # noqa
        handler.seek(0)
        matches = list(grep.find_in_file(handler.name))
        assert len(matches) == 1
        assert matches[0].element == "foo"
Exemple #2
0
def test_find_in_file_oneliner():
    with tempfile.NamedTemporaryFile("w+") as handler:
        handler.write(
            '''# Raincoat: pypi package: BLA==1.2.3 path: yo/yeah.py element: foo'''
        )  # noqa
        handler.seek(0)
        matches = list(grep.find_in_file(handler.name))
        assert len(matches) == 1
Exemple #3
0
def test_find_in_file(match_class):
    with tempfile.NamedTemporaryFile("w+") as handler:
        handler.write("""
            # Raincoat: pypi package: BLA==1.2.3 path: yo/yeah.py element: foo
        """)
        handler.seek(0)
        matches = list(grep.find_in_file(handler.name))
        assert len(matches) == 1
Exemple #4
0
def test_find_in_file_encoding(match_class, caplog):
    with tempfile.NamedTemporaryFile("wb+") as handler:
        handler.write(b"""
            b"# coding: iso-8859-5
            # (Unlikely to be the default encoding for most testers.)
            # \xb1\xb6\xff\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8
            # \xe9\xea\xeb\xec\xed\xee\xef <- Cyrillic characters
            u = '\xae\xe2\xf0\xc4'
            "

        """)
        handler.seek(0)
        matches = list(grep.find_in_file(handler.name))

    assert len(matches) == 0
    assert caplog.record_tuples == [("raincoat.grep", logging.WARNING,
                                     "Unable to read non-utf-8 file")]