示例#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
示例#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'
示例#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
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
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
def test_string_io():
    string_io = io.StringIO()
    config = Config(out=string_io)
    contents = u'stuff'
    config.write(contents)
    assert string_io.getvalue() == contents