Beispiel #1
0
    def test_clone(self):
        doc = Document.clone(self.path)
        self.assertIn('browse-ocrd-clone-', doc.workspace.directory)
        self.assertEqual(str(self.path), doc.baseurl_mets)

        original_files = self.path.parent.rglob('*.*')
        cloned_files = Path(doc.workspace.directory).rglob('*.*')
        for original, cloned in zip(sorted(original_files),
                                    sorted(cloned_files)):
            self.assertEqual(original.read_bytes(), cloned.read_bytes())
Beispiel #2
0
    def test_save(self):
        doc = Document.clone(self.path)
        with TemporaryDirectory(prefix='browse-ocrd-tests') as directory:
            saved_mets = directory + '/mets.xml'
            doc.save_as(saved_mets)
            saved = Document.load(saved_mets)
            self.assertEqual(doc.file_groups, saved.file_groups)
            self.assertEqual(doc.page_ids, saved.page_ids)
            self.assertEqual(doc.workspace.mets.unique_identifier,
                             saved.workspace.mets.unique_identifier)

            for page_id in doc.page_ids:
                for file_group, mime in doc.file_groups_and_mimetypes:
                    original_file = doc.files_for_page_id(
                        page_id, file_group, mime)[0]
                    saved_file = saved.files_for_page_id(
                        page_id, file_group, mime)[0]
                    self.assertEqual(original_file, saved_file)
Beispiel #3
0
    def test_reorder_with_wrong_ids_raises_value_error(self):
        doc = Document.clone(self.path)
        with self.assertRaises(ValueError) as context:
            doc.reorder(['PHYS_0021', 'PHYS_0017'])

        self.assertIn('page_ids do not match', str(context.exception))
Beispiel #4
0
 def test_reorder(self):
     doc = Document.clone(self.path)
     doc.reorder(['PHYS_0020', 'PHYS_0017'])
     self.assertEqual(['PHYS_0020', 'PHYS_0017'], doc.page_ids)
Beispiel #5
0
 def test_modify_when_editable(self):
     doc = Document.clone(self.path)
     doc.reorder(['PHYS_0020', 'PHYS_0017'])
Beispiel #6
0
 def test_delete(self):
     doc = Document.clone(self.path)
     doc.delete_page('PHYS_0017')
     self.assertEqual(['PHYS_0020'], doc.page_ids)