Beispiel #1
0
    def test_blank_line(self):
        s = Stanza(none='', one='\n', two='\n\n')
        self.assertEqual(s.to_string(), b"""\
none:\x20
one:\x20
\t
two:\x20
\t
\t
""")
        s2 = read_stanza(s.to_lines())
        self.assertEqual(s, s2)
Beispiel #2
0
    def test_whitespace_value(self):
        s = Stanza(space=' ', tabs='\t\t\t', combo='\n\t\t\n')
        self.assertEqual(s.to_string(), b"""\
combo:\x20
\t\t\t
\t
space:\x20\x20
tabs: \t\t\t
""")
        s2 = read_stanza(s.to_lines())
        self.assertEqual(s, s2)
        self.rio_file_stanzas([s])
Beispiel #3
0
    def generate(self, to_file):
        info = Stanza()
        revision_id = self._get_revision_id()
        if revision_id != NULL_REVISION:
            info.add('revision-id', revision_id)
            rev = self._branch.repository.get_revision(revision_id)
            info.add('date', create_date_str(rev.timestamp, rev.timezone))
            try:
                revno = self._get_revno_str(revision_id)
            except errors.GhostRevisionsHaveNoRevno:
                revno = None
            for hook in RioVersionInfoBuilder.hooks['revision']:
                hook(rev, info)
        else:
            revno = '0'

        info.add('build-date', create_date_str())
        if revno is not None:
            info.add('revno', revno)

        if self._branch.nick is not None:
            info.add('branch-nick', self._branch.nick)

        if self._check or self._include_file_revs:
            self._extract_file_revisions()

        if self._check:
            if self._clean:
                info.add('clean', 'True')
            else:
                info.add('clean', 'False')

        if self._include_history:
            log = Stanza()
            for (revision_id, message, timestamp,
                 timezone) in self._iter_revision_history():
                log.add('id', revision_id)
                log.add('message', message)
                log.add('date', create_date_str(timestamp, timezone))
            info.add('revisions', log)

        if self._include_file_revs:
            files = Stanza()
            for path in sorted(self._file_revisions.keys()):
                files.add('path', path)
                files.add('revision', self._file_revisions[path])
            info.add('file-revisions', files)

        to_file.write(info.to_string())
Beispiel #4
0
 def test_empty_value(self):
     """Serialize stanza with empty field"""
     s = Stanza(empty='')
     self.assertEquals(s.to_string(), b"empty: \n")
Beispiel #5
0
 def test_backslash(self):
     s = Stanza(q='\\')
     t = s.to_string()
     self.assertEqual(t, b'q: \\\n')
     s2 = read_stanza(s.to_lines())
     self.assertEqual(s, s2)