summaryrefslogtreecommitdiff
path: root/fastimport
diff options
context:
space:
mode:
authormasklinn <bitbucket.org@masklinn.net>2014-04-27 18:21:56 +0200
committermasklinn <bitbucket.org@masklinn.net>2014-04-27 18:21:56 +0200
commit98c69166cf6dda2026efea57943091b10025e5ce (patch)
tree3eaa98a893ffa44103951b3f629a335915effa1d /fastimport
parent2717e4913afb982d9916e5051789e89f042060c9 (diff)
downloadpython-fastimport-git-98c69166cf6dda2026efea57943091b10025e5ce.tar.gz
Authorship information as a namedtuple
* serialization should remain predicated upon a 4-tuple, as users may create and set 4-tuples for authorship info * added a fake time to parser test to test for namedtuple
Diffstat (limited to 'fastimport')
-rw-r--r--fastimport/parser.py5
-rw-r--r--fastimport/tests/test_parser.py26
2 files changed, 22 insertions, 9 deletions
diff --git a/fastimport/parser.py b/fastimport/parser.py
index cff8614..5f81eef 100644
--- a/fastimport/parser.py
+++ b/fastimport/parser.py
@@ -159,6 +159,7 @@ The grammar is:
"""
+import collections
import re
import sys
@@ -551,7 +552,7 @@ class ImportParser(LineBasedParser):
# the data at this level just in case.
if self.user_mapper:
name, email = self.user_mapper.map_name_and_email(name, email)
- return (name, email, when[0], when[1])
+ return Authorship(name, email, when[0], when[1])
def _name_value(self, s):
"""Parse a (name,value) tuple from 'name value-length value'."""
@@ -617,3 +618,5 @@ def _unquote_c_string(s):
"""replace C-style escape sequences (\n, \", etc.) with real chars."""
# HACK: Python strings are close enough
return s.decode('string_escape', 'replace')
+
+Authorship = collections.namedtuple('Authorship', 'name email timestamp timezone')
diff --git a/fastimport/tests/test_parser.py b/fastimport/tests/test_parser.py
index 865baaa..ff0b8e1 100644
--- a/fastimport/tests/test_parser.py
+++ b/fastimport/tests/test_parser.py
@@ -16,7 +16,7 @@
"""Test the Import parsing"""
import StringIO
-
+import time
import unittest
from fastimport import (
@@ -143,8 +143,14 @@ data 17
multi-author test
"""
-
+_timefunc = time.time
class TestImportParser(unittest.TestCase):
+ def setUp(self):
+ self.fake_time = 42.0123
+ time.time = lambda: self.fake_time
+ def tearDown(self):
+ time.time = _timefunc
+ del self.fake_time
def test_iter_commands(self):
s = StringIO.StringIO(_sample_import_text)
@@ -155,6 +161,7 @@ class TestImportParser(unittest.TestCase):
if cmd.name == 'commit':
for fc in cmd.iter_files():
result.append(fc)
+
self.assertEqual(len(result), 17)
cmd1 = result.pop(0)
self.assertEqual('progress', cmd1.name)
@@ -176,9 +183,14 @@ class TestImportParser(unittest.TestCase):
self.assertEqual('2', cmd4.mark)
self.assertEqual(':2', cmd4.id)
self.assertEqual('initial import', cmd4.message)
- self.assertEqual('bugs bunny', cmd4.committer[0])
- self.assertEqual('bugs@bunny.org', cmd4.committer[1])
- # FIXME: check timestamp and timezone as well
+
+ self.assertEqual(('bugs bunny', 'bugs@bunny.org', self.fake_time, 0), cmd4.committer)
+ # namedtuple attributes
+ self.assertEqual('bugs bunny', cmd4.committer.name)
+ self.assertEqual('bugs@bunny.org', cmd4.committer.email)
+ self.assertEqual(self.fake_time, cmd4.committer.timestamp)
+ self.assertEqual(0, cmd4.committer.timezone)
+
self.assertEqual(None, cmd4.author)
self.assertEqual(11, cmd4.lineno)
self.assertEqual('refs/heads/master', cmd4.ref)
@@ -194,9 +206,7 @@ class TestImportParser(unittest.TestCase):
self.assertEqual(None, cmd5.mark)
self.assertEqual('@19', cmd5.id)
self.assertEqual('second commit', cmd5.message)
- self.assertEqual('', cmd5.committer[0])
- self.assertEqual('bugs@bunny.org', cmd5.committer[1])
- # FIXME: check timestamp and timezone as well
+ self.assertEqual(('', 'bugs@bunny.org', self.fake_time, 0), cmd5.committer)
self.assertEqual(None, cmd5.author)
self.assertEqual(19, cmd5.lineno)
self.assertEqual('refs/heads/master', cmd5.ref)