MAJOR=4
MINOR=38
DEVNAME=tty38
  C   ˆl–Ðz¾”*ClÊ
€vãO\l
bÑ¿�þZfR,ÙËlÊè%#ÀþÊ„­¯É_ŠI|¥�+Wé3ž¯ÂÇ ?÷     # Copyright (C) 2009 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""Test how Commands are displayed"""

from unittest import TestCase

from fastimport.helpers import (
    utf8_bytes_string,
    )

from fastimport import (
    commands,
    )


class TestBlobDisplay(TestCase):

    def test_blob(self):
        c = commands.BlobCommand(b"1", b"hello world")
        self.assertEqual(b"blob\nmark :1\ndata 11\nhello world", bytes(c))

    def test_blob_no_mark(self):
        c = commands.BlobCommand(None, b"hello world")
        self.assertEqual(b"blob\ndata 11\nhello world", bytes(c))


class TestCheckpointDisplay(TestCase):

    def test_checkpoint(self):
        c = commands.CheckpointCommand()
        self.assertEqual(b'checkpoint', bytes(c))


class TestCommitDisplay(TestCase):

    def test_commit(self):
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
        committer = (b'Joe Wong', b'joe@example.com', 1234567890, -6 * 3600)
        c = commands.CommitCommand(
            b"refs/heads/master", b"bbb", None, committer,
            b"release v1.0", b":aaa", None, None)
        self.assertEqual(
            b"commit refs/heads/master\n"
            b"mark :bbb\n"
            b"committer Joe Wong <joe@example.com> 1234567890 -0600\n"
            b"data 12\n"
            b"release v1.0\n"
            b"from :aaa",
            bytes(c))

    def test_commit_unicode_committer(self):
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
        name = u'\u013d\xf3r\xe9m \xcdp\u0161\xfam'

        commit_utf8 = utf8_bytes_string(
            u"commit refs/heads/master\n"
            u"mark :bbb\n"
            u"committer %s <test@example.com> 1234567890 -0600\n"
            u"data 12\n"
            u"release v1.0\n"
            u"from :aaa" % (name,)
        )

        committer = (name, b'test@example.com', 1234567890, -6 * 3600)
        c = commands.CommitCommand(
            b'refs/heads/master', b'bbb', None, committer,
            b'release v1.0', b':aaa', None, None)

        self.assertEqual(commit_utf8, bytes(c))

    def test_commit_no_mark(self):
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
        committer = (b'Joe Wong', b'joe@example.com', 1234567890, -6 * 3600)
        c = commands.CommitCommand(
            b'refs/heads/master', None, None, committer,
            b'release v1.0', b':aaa', None, None)
        self.assertEqual(
            b"commit refs/heads/master\n"
            b"committer Joe Wong <joe@example.com> 1234567890 -0600\n"
            b"data 12\n"
            b"release v1.0\n"
            b"from :aaa",
            bytes(c))

    def test_commit_no_from(self):
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
        committer = (b'Joe Wong', b'joe@example.com', 1234567890, -6 * 3600)
        c = commands.CommitCommand(
            b"refs/heads/master", b"bbb", None, committer,
            b"release v1.0", None, None, None)
        self.assertEqual(
            b"commit refs/heads/master\n"
            b"mark :bbb\n"
            b"committer Joe Wong <joe@example.com> 1234567890 -0600\n"
            b"data 12\n"
            b"release v1.0",
            bytes(c))

    def test_commit_with_author(self):
        # user tuple is (name, email, secs-since-epoch, secs-offset-from-utc