1 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
 
   2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
 
   5 from librarian import NoDublinCore
 
   6 from librarian.builders import builders
 
   7 from librarian.parser import WLDocument as LegacyWLDocument
 
   8 from librarian.document import WLDocument
 
   9 from .utils import get_fixture
 
  12 class TextTests(unittest.TestCase):
 
  15     def test_transform_legacy(self):
 
  16         expected_output_file_path = get_fixture('text', 'asnyk_miedzy_nami_expected.txt')
 
  18         text = LegacyWLDocument.from_file(
 
  19             get_fixture('text', 'miedzy-nami-nic-nie-bylo.xml')
 
  20         ).as_text().get_bytes().decode('utf-8')
 
  22         with open(expected_output_file_path, 'rb') as f:
 
  23             self.assertEqual(text, f.read().decode('utf-8'))
 
  25     def test_transform(self):
 
  26         expected_output_file_path = get_fixture('text', 'asnyk_miedzy_nami_expected.txt')
 
  29             filename=get_fixture('text', 'miedzy-nami-nic-nie-bylo.xml')
 
  30         ).build(builders['txt']).get_bytes().decode('utf-8')
 
  32         with open(expected_output_file_path, 'rb') as f:
 
  33             self.assertEqual(text, f.read().decode('utf-8'))
 
  36     def test_transform_raw(self):
 
  37         expected_output_file_path = get_fixture('text', 'asnyk_miedzy_nami_expected_raw.txt')
 
  39         text = LegacyWLDocument.from_file(
 
  40             get_fixture('text', 'miedzy-nami-nic-nie-bylo.xml')
 
  41         ).as_text(flags=['raw-text']).get_bytes().decode('utf-8')
 
  43         with open(expected_output_file_path, 'rb') as f:
 
  44             self.assertEqual(text, f.read().decode('utf-8'))
 
  46     def test_no_dublincore(self):
 
  47         with self.assertRaises(NoDublinCore):
 
  48             LegacyWLDocument.from_file(
 
  49                 get_fixture('text', 'asnyk_miedzy_nami_nodc.xml')
 
  52     def test_passing_parse_dublincore_to_transform(self):
 
  53         """Passing parse_dublincore=False to the constructor omits DublinCore parsing."""
 
  54         LegacyWLDocument.from_file(
 
  55             get_fixture('text', 'asnyk_miedzy_nami_nodc.xml'),
 
  56             parse_dublincore=False,