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