Example #1
0
    def setUp(self):
        self.tempdir = tempfile.mkdtemp()
        self.amendment = os.path.join(self.tempdir, "updatebag")
        os.mkdir(self.amendment)
        srcfile = os.path.join(datadir, "samplembag", "data", "trial1.json")
        shutil.copy(srcfile, self.amendment)
        subdir = os.path.join(self.amendment, "trial3")
        os.mkdir(subdir)
        shutil.copy(srcfile, subdir)

        bagit.make_bag(self.amendment)

        self.amendee = os.path.join(datadir, "samplembag.zip")
        self.amender = amend.Amender(self.amendee, self.amendment)
Example #2
0
    def test_ctor(self):
        self.assertTrue(isinstance(self.amender._oldhead, bagit.Bag))
        self.assertTrue(self.amender._oldhead.is_head_multibag)
        self.assertTrue(isinstance(self.amender._newhead, mbag.HeadBag))
        self.assertIsNone(self.amender._pid)
        self.assertIsNone(self.amender._comm)
        self.assertEqual(self.amender._info, [])

        self.amender = amend.Amender(self.amendee, self.amendment,
                                     "foo://goob")
        self.assertTrue(isinstance(self.amender._oldhead, bagit.Bag))
        self.assertTrue(self.amender._oldhead.is_head_multibag)
        self.assertTrue(isinstance(self.amender._newhead, mbag.HeadBag))
        self.assertEqual(self.amender._pid, "foo://goob")
        self.assertIsNone(self.amender._comm)
        self.assertEqual(self.amender._info, [])

        self.amender = amend.Amender(self.amendee, self.amendment,
                                     "foo://goob", "this is version 3")
        self.assertTrue(isinstance(self.amender._oldhead, bagit.Bag))
        self.assertTrue(self.amender._oldhead.is_head_multibag)
        self.assertTrue(isinstance(self.amender._newhead, mbag.HeadBag))
        self.assertEqual(self.amender._pid, "foo://goob")
        self.assertEqual(self.amender._comm, "this is version 3")
        self.assertEqual(self.amender._info, [])

        info = ["a", "b"]
        self.amender = amend.Amender(self.amendee, self.amendment,
                                     "foo://goob", "this is version 2", info)
        self.assertTrue(isinstance(self.amender._oldhead, bagit.Bag))
        self.assertTrue(self.amender._oldhead.is_head_multibag)
        self.assertTrue(isinstance(self.amender._newhead, mbag.HeadBag))
        self.assertEqual(self.amender._pid, "foo://goob")
        self.assertEqual(self.amender._comm, "this is version 2")
        self.assertEqual(self.amender._info, ["a", "b"])
        info[1] = "c"
        self.assertEqual(self.amender._info, ["a", "b"])
Example #3
0
    def test_init_member_bags2(self):
        # test when the amendee is not natively a head bag
        self.amendee = os.path.join(self.tempdir, "gooberbag")
        src = os.path.join(datadir, "samplembag", "data")
        shutil.copytree(src, self.amendee)
        bagit.make_bag(self.amendee)
        self.amender = amend.Amender(self.amendee, self.amendment)

        membagsfile = os.path.join(self.amender._newheaddir, "multibag",
                                   "member-bags.tsv")
        self.assertTrue(not os.path.exists(membagsfile))

        self.amender._init_member_bags()
        self.assertTrue(not os.path.exists(membagsfile))
        self.assertEqual(self.amender._newhead.member_bag_names, ["gooberbag"])
Example #4
0
    def test_init_member_bags3(self):
        # test when the amendment happens to be head-bag conformant
        self.amendee = os.path.join(self.tempdir, "gooberbag")
        src = os.path.join(datadir, "samplembag", "data")
        shutil.copytree(src, self.amendee)
        bagit.make_bag(self.amendee)
        amend.make_single_multibag(self.amendment)
        self.amender = amend.Amender(self.amendee, self.amendment)

        membagsfile = os.path.join(self.amender._newheaddir, "multibag",
                                   "member-bags.tsv")
        self.assertTrue(os.path.exists(membagsfile))

        self.amender._init_member_bags()
        self.assertTrue(not os.path.exists(membagsfile))
        self.assertEqual(self.amender._newhead.member_bag_names, ["gooberbag"])
Example #5
0
    def test_init_multibag_info3(self):
        # test when src has deprecations
        self.amendee = os.path.join(self.tempdir, "gooberbag")
        src = os.path.join(datadir, "samplembag")
        shutil.copytree(src, self.amendee)
        bag = bagit.Bag(self.amendee)
        bag.info['Multibag-Head-Deprecates'] = ["0.1", "0.5"]
        bag.save()
        self.amender = amend.Amender(self.amendee, self.amendment)

        self.assertNotIn('Multibag-Head-Deprecates',
                         self.amender._newhead.info)

        self.amender._init_multibag_info()
        self.assertEqual(
            self.amender._newhead.info.get('Multibag-Head-Deprecates'),
            ["0.1", "0.5", "1.0"])
Example #6
0
    def test_init_file_lookup2(self):
        # test when the amendee is not natively a head bag
        self.amendee = os.path.join(self.tempdir, "gooberbag")
        src = os.path.join(datadir, "samplembag", "data")
        shutil.copytree(src, self.amendee)
        bagit.make_bag(self.amendee)
        self.amender = amend.Amender(self.amendee, self.amendment)

        lufile = os.path.join(self.amender._newheaddir, "multibag",
                              "file-lookup.tsv")
        self.assertTrue(not os.path.exists(lufile))

        self.amender._init_multibag_info()
        self.amender._init_file_lookup()
        self.assertTrue(not os.path.exists(lufile))
        self.assertEqual(self.amender._newhead.lookup_file("data/trial1.json"),
                         "gooberbag")
Example #7
0
    def test_init_file_lookup3(self):
        # test when the amendment happens to be head-bag conformant
        self.amendee = os.path.join(self.tempdir, "gooberbag")
        src = os.path.join(datadir, "samplembag", "data")
        shutil.copytree(src, self.amendee)
        bagit.make_bag(self.amendee)
        amend.make_single_multibag(self.amendment)
        self.amender = amend.Amender(self.amendee, self.amendment)

        lufile = os.path.join(self.amender._newheaddir, "multibag",
                              "file-lookup.tsv")
        self.assertTrue(os.path.exists(lufile))

        self.amender._init_file_lookup()
        self.assertTrue(not os.path.exists(lufile))
        self.assertEqual(self.amender._newhead.lookup_file("data/trial1.json"),
                         "gooberbag")