def _to_lines(self, base_revision=False): """Serialize as a list of lines :return: a list of lines """ time_str = timestamp.format_patch_date(self.time, self.timezone) stanza = rio.Stanza(revision_id=self.revision_id, timestamp=time_str, target_branch=self.target_branch, testament_sha1=self.testament_sha1) for key in ('source_branch', 'message'): if self.__dict__[key] is not None: stanza.add(key, self.__dict__[key]) if base_revision: stanza.add('base_revision_id', self.base_revision_id) lines = ['# ' + self._format_string + '\n'] lines.extend(rio.to_patch_lines(stanza)) lines.append('# \n') return lines
def test_repeated(self): s = rio.Stanza() s.add("foo", "bar") s.add("foo", "foo") self.assertReadStanza(s, ["foo: bar\n", "foo: foo\n"])
def test_multi_line(self): self.assertReadStanza(rio.Stanza(foo="bar\nbla"), ["foo: bar\n", "\tbla\n"])
def test_simple(self): self.assertReadStanza(rio.Stanza(foo="bar"), ["foo: bar\n", ""])
def test_non_ascii_char(self): self.assertReadStanza(rio.Stanza(foo=u"n\xe5me"), [u"foo: n\xe5me\n"])
def test_large(self): value = u"bla" * 9000 self.assertReadStanza(rio.Stanza(foo=value), [u"foo: %s\n" % value])