Пример #1
0
    def test_generic_row_generation(self):
        from metatab import GenericRowGenerator

        url = 'gs://14_nfiTtSiMSjDes6BSiLU-Gsqy8DIdUxpMaH6DswcVQ'

        doc = MetatabDoc(url)

        self.assertEquals('Registered Voters, By County',
                          doc.find_first('root.title').value)

        url = 'http://assets.metatab.org/examples/example-package.xls#meta'

        doc = MetatabDoc(url)

        self.assertEquals('17289303-73fa-437b-97da-2e1ed2cd01fd',
                          doc.find_first('root.identifier').value)
Пример #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'))
Пример #3
0
    def test_find(self):

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

        self.assertEquals('cdph.ca.gov-hci-registered_voters-county',
                          doc.find_first('Root.Identifier').value)