Ejemplo n.º 1
0
 def test_iterate_order(self):
     """Test that the order of appearance in Core file is respected when iterating."""
     # This is also probably tested indirectly elsewhere, but this is the right place :)
     with DwCAReader(sample_data_path('dwca-ids.zip')) as dwca:
         l = list(dwca)
         # Row IDs are ordered like this in core file: id 4-1-3-2
         self.assertEqual(int(l[0].id), 4)
         self.assertEqual(int(l[1].id), 1)
         self.assertEqual(int(l[2].id), 3)
         self.assertEqual(int(l[3].id), 2)
Ejemplo n.º 2
0
    def test_no_cr_left(self):
        """Test no carriage return characters are left at end of line."""

        # We know we have no \n in our test archive, so if we fine one
        # it's probably a character that was left by error when parsing
        # line
        with DwCAReader(sample_data_path('dwca-simple-test-archive.zip')) as simple_dwca:
            for l in simple_dwca:
                for k, v in l.data.items():
                    self.assertFalse(v.endswith("\n"))
Ejemplo n.º 3
0
    def test_archives_without_metadata(self):
        """Ensure we can deal with an archive containing a metafile, but no metadata."""
        with DwCAReader(sample_data_path('dwca-nometadata.zip')) as dwca:
            self.assertIsNone(dwca.metadata)

            # But the data is nevertheless accessible
            rows = list(dwca)
            self.assertEqual(len(rows), 2)
            self.assertEqual('Borneo', rows[0].data[qn('locality')])
            self.assertEqual('Mumbai', rows[1].data[qn('locality')])
Ejemplo n.º 4
0
    def test_metadata(self):
        """A few basic tests on the metadata attribute."""
        with DwCAReader(sample_data_path('dwca-simple-test-archive.zip')) as dwca:
            # Assert metadata is an instance of ElementTree.Element
            self.assertIsInstance(dwca.metadata, ET.Element)

            # Assert we can read basic fields from EML:
            v = (dwca.metadata.find('dataset').find('creator').find('individualName')
                     .find('givenName').text)
            self.assertEqual(v, 'Nicolas')
Ejemplo n.º 5
0
    def test_manual_cleanup_zipped(self):
        """Test no temporary files are left after execution (calling close() manually)."""
        num_files_before = len(os.listdir('.'))

        r = DwCAReader(sample_data_path('dwca-simple-test-archive.zip'))
        r.close()

        num_files_after = len(os.listdir('.'))

        self.assertEqual(num_files_before, num_files_after)
Ejemplo n.º 6
0
    def test_auto_cleanup_zipped(self):
        """Test no temporary files are left after execution (using 'with' statement)."""
        num_files_before = len(os.listdir('.'))

        with DwCAReader(sample_data_path('dwca-simple-test-archive.zip')):
            pass

        num_files_after = len(os.listdir('.'))

        self.assertEqual(num_files_before, num_files_after)
Ejemplo n.º 7
0
    def test_default_values_metafile(self):
        """
        Ensure default values are used when optional attributes are absent in metafile.

        Optional attributes tested here: linesTerminatedBy, fieldsTerminatedBy.
        """
        with DwCAReader(sample_data_path('dwca-meta-default-values')) as dwca:
            # Test iterating on rows...
            for row in dwca:
                self.assertIsInstance(row, CoreRow)
Ejemplo n.º 8
0
 def test_source_is_dwca(self):
     print 'testing source_is_dwca'
     dwca = self.framework.dwca
     dwcareader = None
     try:
         dwcareader = DwCAReader(dwca)
     except:
         dwcareader = None
     s = 'No viable Darwin Core archive found at %s' % dwca
     self.assertIsNotNone(dwcareader, s)
Ejemplo n.º 9
0
    def test_exposes_core_type(self):
        """Test that it exposes the Archive Core Type as type"""

        with DwCAReader(BASIC_ARCHIVE_PATH) as dwca:
            coredescriptor = dwca.descriptor.core
            # dwca-simple-test-archive.zip should be of Occurrence type
            self.assertEqual(coredescriptor.type,
                             'http://rs.tdwg.org/dwc/terms/Occurrence')
            # Check that shortcuts also work
            self.assertEqual(coredescriptor.type, qn('Occurrence'))
Ejemplo n.º 10
0
 def test_implicit_encoding_metadata(self):
     """If the metadata file doesn't specifies encoding, use UTF-8."""
     with DwCAReader(sample_data_path("dwca-simple-dir")) as dwca:
         v = (
             dwca.metadata.find("dataset")
             .find("creator")
             .find("individualName")
             .find("surName")
             .text
         )
         self.assertEqual(v, u"Noé")