def setUp(self): super(FileRepositoryFixture, self).setUp() if self.path and os.path.isdir(self.path): self.tempdir = self.path else: self.tempdir = tempfile.mkdtemp() self.addCleanup(shutil.rmtree, self.tempdir) self.repo = file.RepositoryFactory().initialise(self.tempdir)
def test_initialise_non_empty_dir(self): self.useFixture( FileRepositoryFixture(path=self.tempdir, initialise=False)) base = os.path.join(self.tempdir, '.stestr') os.mkdir(base) with open(os.path.join(base, 'foo'), 'wt') as stream: stream.write('1\n') factory = file.RepositoryFactory() self.assertRaises(OSError, factory.initialise, self.tempdir)
def test_initialise_empty_dir(self): self.useFixture( FileRepositoryFixture(path=self.tempdir, initialise=False)) base = os.path.join(self.tempdir, '.stestr') os.mkdir(base) self.assertFalse(os.path.isfile(os.path.join(base, 'format'))) self.repo = file.RepositoryFactory().initialise(self.tempdir) self.assertTrue(os.path.isdir(base)) self.assertTrue(os.path.isfile(os.path.join(base, 'format'))) with open(os.path.join(base, 'format')) as stream: contents = stream.read() self.assertEqual("1\n", contents) with open(os.path.join(base, 'next-stream')) as stream: contents = stream.read() self.assertEqual("0\n", contents)
def test_initialise_expands_user_directory(self): short_path = self.useFixture(HomeDirTempDir()).short_path repo = file.RepositoryFactory().initialise(short_path) self.assertTrue(os.path.exists(repo.base))
def test_open_expands_user_directory(self): short_path = self.useFixture(HomeDirTempDir()).short_path repo1 = file.RepositoryFactory().initialise(short_path) repo2 = file.RepositoryFactory().open(short_path) self.assertEqual(repo1.base, repo2.base)