def test_convert_new(self): # create the data self.bagdir = os.path.join(self.tempdir, "sampledata") self.assertTrue(not os.path.isdir(self.bagdir)) dm = mkdata.DatasetMaker( self.bagdir, { 'totalsize': 15, 'totalfiles': 3, 'files': [{ 'totalsize': 10, 'totalfiles': 2 }], 'dirs': [{ 'totalsize': 5, 'totalfiles': 1 }] }) dm.fill() self.assertTrue(os.path.isdir(self.bagdir)) # turn it into a bag bag = bagit.make_bag(self.bagdir) self.assertTrue(bag.validate()) mbdir = os.path.join(self.bagdir, 'multibag') self.assertTrue(not os.path.exists(mbdir)) # convert it to a multibag self.mkr = amend.SingleMultibagMaker(self.bagdir) self.mkr.convert("1.5", "doi:XXXX/11111") self.assertTrue(os.path.exists(mbdir)) # validate it as a head bag valid8.validate_headbag(self.bagdir)
def setUp(self): self.tempdir = tempfile.mkdtemp() self.bagdir = os.path.join(self.tempdir, "samplebag") shutil.copytree(os.path.join(datadir, "samplembag"), self.bagdir) shutil.rmtree(os.path.join(self.bagdir, "multibag")) bag = bagit.Bag(self.bagdir) rmtag = [] for tag in bag.info: if tag.startswith('Multibag-'): rmtag.append(tag) for tag in rmtag: del bag.info[tag] bag.save() self.mkr = amend.SingleMultibagMaker(self.bagdir)
def test_write_member_bags_alt(self): self.mkr = amend.SingleMultibagMaker(self.bagdir, "goober") mbdir = os.path.join(self.bagdir, "goober") mbfile = os.path.join(mbdir, 'member-bags.tsv') self.assertTrue(not os.path.exists(mbdir)) self.mkr.write_member_bags("doi:XXXX/11111") self.assertTrue(os.path.exists(mbdir)) self.assertTrue(os.path.exists(mbfile)) with open(mbfile) as fd: lines = fd.readlines() self.assertEqual(len(lines), 1) parts = lines[0].strip().split("\t") self.assertEqual(parts[0], os.path.basename(self.bagdir)) self.assertEqual(parts[1], "doi:XXXX/11111")
def test_ctor(self): self.assertEqual(self.mkr.bagdir, self.bagdir) self.assertEqual(self.mkr.bag.multibag_tag_dir, "multibag") self.mkr = amend.SingleMultibagMaker(self.bagdir, "goober") self.assertEqual(self.mkr.bag.multibag_tag_dir, "goober")