コード例 #1
0
ファイル: test_snoop.py プロジェクト: xzhou2018/snoop
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
コード例 #2
0
ファイル: test_snoop.py プロジェクト: xzhou2018/snoop
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'
コード例 #3
0
ファイル: test_snoop.py プロジェクト: xcbat/snoop
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'
コード例 #4
0
ファイル: test_snoop.py プロジェクト: xcbat/snoop
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
コード例 #5
0
ファイル: test_snoop.py プロジェクト: xzhou2018/snoop
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
コード例 #6
0
ファイル: test_snoop.py プロジェクト: xzhou2018/snoop
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'
コード例 #7
0
ファイル: watch_extras.py プロジェクト: xzhou2018/snoop
def main():
    Config(watch_extras=watch_type).snoop(foo)()
    Config(replace_watch_extras=watch_type).snoop(foo)()
コード例 #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 = """
"""
コード例 #9
0
ファイル: test_snoop.py プロジェクト: xzhou2018/snoop
def test_string_io():
    string_io = io.StringIO()
    config = Config(out=string_io)
    contents = u'stuff'
    config.write(contents)
    assert string_io.getvalue() == contents
コード例 #10
0
ファイル: no_columns.py プロジェクト: xzhou2018/snoop
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
"""
コード例 #11
0
ファイル: method_and_prefix.py プロジェクト: ttamg/snoop
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()
コード例 #12
0
ファイル: threads.py プロジェクト: xzhou2018/snoop
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():
コード例 #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()