def assert_read_write_file(self, path, data): """ Assert that file can be written and read back from builder """ assert not builder.exists(path) builder.write(path, data) assert builder.exists(path) assert builder.read(path) == data
def test_temp_builder(self, temp_builder): """ basic sanity test """ path = "TestTempBuilder.test" assert not builder.exists(path), "file should not exist yet" builder.write(path, "test file") assert builder.exists(path), "file should exist now"
def test_reset(temp_builder): """ Test resetting (clearing) the builder directory """ path = "reset_test" builder.write(path, "reset test") assert builder.exists(path) builder.reset() assert not builder.exists(path)
def test_temp_builder_leak_test(self, i, temp_builder): """ Test that builds are not leaking. Both iterations of the test write to the same file. The first test should clean the file. The 2nd test may only pass if the file does not exist. Note that this only proves that one of the following are working: - temp_builder has a random directory - the files were cleaned up Ideally, both would happen but the main concern is that tasks don't leak. """ path = "TestTempBuilder.leak_test" assert not builder.exists(path), "file should not exist yet" builder.write(path, "This file should be cleaned up at the end of the test") assert builder.exists(path), "file should exist now"
def save(self): state = self.state() data = json.dumps(state) builder.write(self.file_path(), data)