Exemple #1
0
    def test_versions(self):

        doc = MetatabDoc(test_data('example1.csv'))

        self.assertEqual('201404', doc.find_first_value('Root.Version'))
        self.assertEqual('201409',
                         doc.as_version('+5').find_first_value('Root.Version'))
        self.assertEqual('201399',
                         doc.as_version('-5').find_first_value('Root.Version'))
        self.assertEqual(
            'foobar',
            doc.as_version('foobar').find_first_value('Root.Version'))
Exemple #2
0
    def test_update_name(self):
        import datapackage
        from metatab.datapackage import convert_to_datapackage

        for fn in ('name.csv', 'name2.csv'):

            doc = MetatabDoc(test_data(fn))

            updates = doc.update_name()

            name = doc.find_first_value("Root.Name")

            self.assertEquals('example.com-foobar-2017-ca-people-1', name)
            self.assertEquals(['Changed Name'], updates)

            try:
                doc.remove_term(doc.find_first('Root.Dataset'))
            except ValueError:
                nv = doc.find_first('Root.Name')
                nv.remove_child(nv.find_first('Name.Dataset'))

            updates = doc.update_name()

            self.assertIn("No Root.Dataset, so can't update the name", updates)

            doc.find_first('Root.Name').value = None

            updates = doc.update_name()

            self.assertIn('Setting the name to the identifier', updates)

            doc.find_first('Root.Name').value = None
            doc.find_first('Root.Identifier').value = None

            updates = doc.update_name()

            self.assertIn(
                'Failed to find DatasetName term or Identity term. Giving up',
                updates)

            self.assertIsNone(doc.get_value('Root.Name'))