Exemplo n.º 1
0
    def a():
        from sample8errors import silenced1, silenced2, silenced3, silenced4, notsilenced

        silenced1()
        print("Done silenced1")
        silenced2()
        print("Done silenced2")
        silenced3()
        print("Done silenced3")
        silenced4()
        print("Done silenced4")

        try:
            notsilenced()
        except ValueError:
            print("Done not silenced")
Exemplo n.º 2
0
def test_profile(LineMatcher, options):
    stream = StringIO()
    with hunter.trace(action=ProfileAction(stream=stream), **options):
        from sample8errors import notsilenced
        from sample8errors import silenced1
        from sample8errors import silenced3
        from sample8errors import silenced4

        silenced1()
        print('Done silenced1')
        silenced3()
        print('Done silenced3')
        silenced4()
        print('Done silenced4')

        try:
            notsilenced()
        except ValueError:
            print('Done not silenced')

    lm = LineMatcher(stream.getvalue().splitlines())
    if 'profile' in options:
        lm.fnmatch_lines([
            "sample8errors.error raised exception: None. Duration: ?.????s",
            "sample8errors.silenced1 returned: None. Duration: ?.????s",
            "sample8errors.error raised exception: None. Duration: ?.????s",
            "sample8errors.silenced3 returned: mwhahaha. Duration: ?.????s",
            "sample8errors.error raised exception: None. Duration: ?.????s",
            "<builtin>.repr raised exception: None. Duration: ?.????s",
            "sample8errors.silenced4 returned: None. Duration: ?.????s",
            "sample8errors.error raised exception: None. Duration: ?.????s",
            "sample8errors.notsilenced raised exception: None. Duration: ?.????s",
        ])
    else:
        lm.fnmatch_lines([
            "sample8errors.error raised exception: (*RuntimeError*, *). Duration: ?.????s",
            "sample8errors.silenced1 returned: None. Duration: ?.????s",
            "sample8errors.error raised exception: (*RuntimeError*, *). Duration: ?.????s",
            "sample8errors.silenced3 returned: mwhahaha. Duration: ?.????s",
            "sample8errors.error raised exception: (*RuntimeError*, *). Duration: ?.????s",
            "sample8errors.silenced4 returned: None. Duration: ?.????s",
            "sample8errors.error raised exception: (*RuntimeError*, *). Duration: ?.????s",
            "sample8errors.notsilenced raised exception: (*ValueError(RuntimeError*, *). Duration: ?.????s",
        ])