def test_first_inexistent_directory_traversing_nondir(self): """Tests the output of first_inexistent_directory when one of the intermediate directories is actually a file.""" os.makedirs(self.foo, 0o0755) with open(self.bar, 'a'): pass with self.assertRaises(FileExistsError): first_inexistent_directory(self.baz)
def test_makedirs_race_condition(self): """Mocks os.makedirs behaviour to create willingly a race condition in filesystem.makedirs and test it.""" first_inexistent_directory(self.baz) makedirs(self.bar) with unittest.mock.patch('os.makedirs', new=fake_makedirs): with self.assertRaises(FileExistsError): makedirs(self.baz)
def test_first_inexistent_directory(self): """Tests the output of first_inexistent_directory""" upwards_dir = first_inexistent_directory(self.baz) self.assertEqual(upwards_dir, self.foo)