Esempio n. 1
0
    def test_pos_02(self):
        "Check fd output with no raw comment"

        tre = TxtRecordEntry(["mtag:", [" iline"], ["# Comment"] ])
        tre.set_comment("A new comment")
        fd = StringIO.StringIO()
        tre.write_fd(fd)

        expres = "mtag: iline\n# A new comment\n"
        assert(fd.getvalue()==expres)
Esempio n. 2
0
    def test_pos_01(self):
        "Check format entry with existing comment"
        tre = TxtRecordEntry(["mtag:", [" iline"], ["# Comment"] ])

        r = TxtRecordEntry.format_entry(tre)
        expres = "mtag: iline\n#  Comment\n"
        assert(r==expres)
Esempio n. 3
0
 def to_string(self):
     s = TxtParser.add_newlines(self.comment_raw)
     for l in self:
         # There is the need to check for the type: only the
         # TxtRecordEntry provides a (for this method) usable
         # output.
         if isinstance(l, TxtRecordEntry):
             s += l.to_string()
         else:
             # If this is another RecordEntry, at least get some
             # infos from this.
             s += TxtRecordEntry.format_entry(l)
     return s
Esempio n. 4
0
 def to_string(self):
     """Convert to string"""
     rstring = TxtParser.add_newlines(self.comment_raw)
     for line in self:
         # There is the need to check for the type: only the
         # TxtRecordEntry provides a (for this method) usable
         # output.
         if isinstance(line, TxtRecordEntry):
             rstring += line.to_string()
         else:
             # If this is another RecordEntry, at least get some
             # infos from this.
             rstring += TxtRecordEntry.format_entry(line)
     return rstring
Esempio n. 5
0
    def test_pos_02(self):
        "Check fd output with no raw comment"

        tre = TxtRecordEntry(["mtag:", [" iline"], ["# Comment"]])
        tre.set_comment("A new comment")
        fd = StringIO.StringIO()
        tre.write_fd(fd)

        expres = "mtag: iline\n# A new comment\n"
        assert (fd.getvalue() == expres)
Esempio n. 6
0
    def parse(self, s, rid):
        # Split up into lines
        sl = s.split("\n")
        self.check_line_length(sl, rid)
        self.maybe_remove_last_empty_line(sl)
        self.comment_raw = TxtParser.extract_record_comment(sl)
        self.set_comment(TxtParser.extract_comment(self.comment_raw))

        success, rp = TxtParser.split_entries(sl, rid, self,
                                              len(self.comment_raw) + 1)
        # If there was an error during the split already - stop
        # processing here
        if not success:
            self._set_not_usable()
            return

        for i in rp:
            self.append(TxtRecordEntry(i))
        return