Пример #1
0
 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
Пример #2
0
 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"
Пример #3
0
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)
Пример #4
0
 def assert_read_write_file(self, path, data):
     """
     Assert that file can be written and read back from filesystem
     """
     full_path = builder.get_path(path)
     assert not builder.exists(path)
     filesystem.write_file(full_path, data)
     assert builder.exists(path)
     assert filesystem.read_file(full_path) == data
Пример #5
0
    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"
Пример #6
0
 def test_path_doesnt_exist(self, temp_builder):
     """
     Test writing to file when the directories do not exist
     """
     path = "TestReadWrite/test_path_doesnt_exist"
     file = f"{path}/file"
     assert not builder.exists(path)
     self.assert_read_write_file(file, "test_path_doesnt_exist")
Пример #7
0
 def test_path_exists(self, temp_builder):
     """
     Test writing to file when the directories already exist
     """
     path = "builder.TestReadWrite/test_path_exists"
     file = f"{path}/file"
     full_path = builder.get_path(path)
     filesystem.mkdir(full_path)
     assert builder.exists(path)
     self.assert_read_write_file(file, "test_path_exists")
Пример #8
0
 def saved_state(self):
     """
     Retrieved saved state, if any.  If task has not been run successfully
     it's state will be None.
     :return: state object
     """
     file_path = self.file_path()
     if builder.exists(file_path):
         return json.loads(builder.read(file_path))
     else:
         return None