@@ -0,0 +1,1429 @@
+# Copyright (c) 2015 Ultimaker B.V.%0A# Uranium is released under the terms of the AGPLv3 or higher.%0A%0Aimport unittest%0Aimport os.path%0Aimport tempfile%0A%0Afrom multiprocessing import Pool%0A%0Afrom UM.SaveFile import SaveFile%0A%0Awrite_count = 0%0A%0Adef write_dual(path):%0A    with SaveFile(path, %22w%22) as f:%0A        f.write(%22test file%22)%0A%0Aclass TestSaveFile(unittest.TestCase):%0A    def setUp(self):%0A        self._temp_dir = tempfile.TemporaryDirectory()%0A%0A    def tearDown(self):%0A        self._temp_dir.cleanup()%0A        self._temp_dir = None%0A%0A    def test_singleWrite(self):%0A        path = os.path.join(self._temp_dir.name, %22single_write%22)%0A        with SaveFile(path, %22w%22) as f:%0A            f.write(%22test file%22)%0A%0A        with open(path) as f:%0A            self.assertEqual(f.readline(), %22test file%22)%0A%0A    def test_multiWrite(self):%0A        path = os.path.join(self._temp_dir.name, %22dual_write%22)%0A%0A        # Start two processes that try to write to the same file%0A        with Pool(processes = 2) as p:%0A            p.apply_async(write_dual, %5Bpath%5D)%0A            p.apply(write_dual, %5Bpath%5D)%0A%0A        # Once done, there should be just one file%0A        self.assertEqual(len(os.listdir(self._temp_dir.name)), 1)%0A%0A        # And file contents should be correct.%0A        with open(path) as f:%0A            data = f.read()%0A            self.assertEqual(len(data), 9)%0A            self.assertEqual(data, %22test file%22)%0A%0Aif __name__ == %22__main__%22:%0A    unittest.main()%0A

Add a test for SaveFile