Esempio n. 1
0
 def extract_body(self, fp, basefile):
     bodystring = fp.read()
     # see comment in extract_head for why we must handle both
     # bytes- and str-files
     if not isinstance(bodystring, str):
         bodystring = bodystring.decode(self.source_encoding)
     reader = TextReader(string=bodystring, linesep=TextReader.DOS)
     reader.autostrip = True
     return reader
Esempio n. 2
0
 def extract_body(self, fp, basefile):
     bodystring = fp.read()
     # see comment in extract_head for why we must handle both
     # bytes- and str-files
     if not isinstance(bodystring, str):
         bodystring = bodystring.decode(self.source_encoding)
     reader = TextReader(string=bodystring, linesep=TextReader.DOS)
     reader.autostrip = True
     return reader
Esempio n. 3
0
    def parametric_test(self, filename):
        self.maxDiff = None
        reader = TextReader(filename=filename, encoding='iso-8859-1',
                              linesep=TextReader.DOS)
        reader.autostrip = True
        # p.lagrum_parser = FakeParser()
        parser = self.p.get_parser("9999:998", reader)
        b = parser(reader)
        elements = self.p._count_elements(b)

        # FIXME: How was this used? Where should we plug
        # skipfragments?
        if 'K' in elements and elements['K'] > 1 and elements['P1'] < 2:
            self.p.skipfragments = [
                ('rinfoex:avdelningnummer', 'rpubl:kapitelnummer'),
                ('rpubl:kapitelnummer', 'rpubl:paragrafnummer')]
        else:
            self.p.skipfragments = [('rinfoex:avdelningnummer',
                                     'rpubl:kapitelnummer')]

        # NB: _construct_ids won't look for references
        self.p.visit_node(b, self.p.construct_id, {'basefile': '9999:998',
                                                   'uris': set()})
        self.p.visit_node(b, self.p.find_definitions, False, debug=False)
        self.p.lagrum_parser.parse_recursive(b)
        self._remove_uri_for_testcases(b)
        resultfilename = filename.replace(".txt", ".xml")
        if os.path.exists(resultfilename):
            with codecs.open(resultfilename, encoding="utf-8") as fp:
                result = fp.read().strip()
            self.assertEqual(result, serialize(b).strip())
        else:
            self.assertEqual("", serialize(b).strip())
        # reset the state of the repo...
        self.p.current_section = '0'
        self.p.current_headline_level = 0