Exemplo n.º 1
0
def test_file_output():
    _, path = mkstemp()
    config = Config(out=path)
    contents = u'stuff'
    config.write(contents)
    with open(path) as output_file:
        output = output_file.read()
    assert output == contents
Exemplo n.º 2
0
def test_no_overwrite_by_default():
    _, path = mkstemp()
    with open(path, 'w') as output_file:
        output_file.write(u'lala')
    config = Config(str(path))
    config.write(u' doo be doo')
    with open(path) as output_file:
        output = output_file.read()
    assert output == u'lala doo be doo'
Exemplo n.º 3
0
def test_no_overwrite_by_default():
    with temp_file_tools.create_temp_folder(prefix='snoop') as folder:
        path = folder / 'foo.log'
        with path.open('w') as output_file:
            output_file.write(u'lala')
        config = Config(str(path))
        config.write(u' doo be doo')
        with path.open() as output_file:
            output = output_file.read()
        assert output == u'lala doo be doo'
Exemplo n.º 4
0
def test_file_output():
    with temp_file_tools.create_temp_folder(prefix='snoop') as folder:
        path = folder / 'foo.log'

        config = Config(out=path)
        contents = u'stuff'
        config.write(contents)
        with path.open() as output_file:
            output = output_file.read()
        assert output == contents
Exemplo n.º 5
0
def test_callable():
    string_io = io.StringIO()

    def write(msg):
        string_io.write(msg)

    string_io = io.StringIO()
    config = Config(out=write)
    contents = u'stuff'
    config.write(contents)
    assert string_io.getvalue() == contents
Exemplo n.º 6
0
def test_overwrite():
    _, path = mkstemp()
    with open(path, 'w') as output_file:
        output_file.write(u'lala')

    config = Config(out=str(path), overwrite=True)
    config.write(u'doo be')
    config.write(u' doo')

    with open(path) as output_file:
        output = output_file.read()
    assert output == u'doo be doo'
Exemplo n.º 7
0
def main():
    Config(watch_extras=watch_type).snoop(foo)()
    Config(replace_watch_extras=watch_type).snoop(foo)()
Exemplo n.º 8
0
from snoop.configuration import Config

from birdseye import eye

config = Config(enabled=False)


@config.spy
def foo():
    assert config.pp(1 + 2) == 3
    assert config.pp(1 + 3, 6) == (4, 6)


def main():
    call_id = eye._last_call_id
    foo()
    assert call_id is eye._last_call_id


expected_output = """
"""
Exemplo n.º 9
0
def test_string_io():
    string_io = io.StringIO()
    config = Config(out=string_io)
    contents = u'stuff'
    config.write(contents)
    assert string_io.getvalue() == contents
Exemplo n.º 10
0
from snoop.configuration import Config

snoop = Config(columns='').snoop


@snoop
def main():
    x = 1
    y = x + 2


expected_output = """
>>> Call to main in File "/path/to_file.py", line 7
    7 | def main():
    8 |     x = 1
    9 |     y = x + 2
 .......... y = 3
 <<< Return value from main: None
"""
Exemplo n.º 11
0
from snoop.configuration import Config

snoop = Config(prefix='ZZZ').snoop


class Baz(object):
    def __init__(self):
        self.x = 2

    @snoop(watch='self.x')
    def square(self):
        foo = 7
        self.x **= 2
        return self


def main():
    baz = Baz()
    baz.square()
Exemplo n.º 12
0
from threading import Thread

from snoop.configuration import Config

snoop = Config(columns='thread').snoop


@snoop
def foo():
    return 1


def run(name):
    thread = Thread(target=foo, name=name)
    thread.start()
    thread.join()


def main():
    run('short')
    run('longername')
    run('short')


expected_output = """
short >>> Call to foo in File "/path/to_file.py", line 9
short    9 | def foo():
short   10 |     return 1
short <<< Return value from foo: 1
longername >>> Call to foo in File "/path/to_file.py", line 9
longername    9 | def foo():
Exemplo n.º 13
0
from snoop.configuration import Config

snoop = Config(
    columns='time thread thread_ident file full_file function function_qualname'
).snoop


def main():
    @snoop
    def foo():
        x = 1
        y = x + 2

    foo()