def test_open_or_use_file_read(): """Check reading from file.""" with NamedTemporaryFile("r") as ro: with open(ro.name, "w") as w: w.write(contents) with open_or_use(ro) as r: assert r.read() == contents
def test_open_or_use_file_write(): """Check writing to file.""" with NamedTemporaryFile("w") as wo: with open_or_use(wo) as w: w.write(contents) wo.flush() assert open(wo.name).read() == contents
def test_open_or_use_string_write(): """Check writing to filename.""" with NamedTemporaryFile("w") as w: w.write(contents) w.flush() with open_or_use(w.name) as r: assert r.read() == contents
def test_open_or_use_string_read(): """Check reading from filename.""" with NamedTemporaryFile("r") as r: with open_or_use(r.name, "w") as w: w.write(contents) assert r.read() == contents