summaryrefslogtreecommitdiff
path: root/fastimport
diff options
context:
space:
mode:
authorFélix Mattrat <mattr.felix@gmail.com>2016-04-14 16:41:48 +0200
committerFélix Mattrat <mattr.felix@gmail.com>2016-04-14 16:41:54 +0200
commitee90b2a6afeebe24da17f5545eda7f0676867cf4 (patch)
tree0fab7606bf2531f38cae2579b776e583d7f67581 /fastimport
parent1980993afa14bf8bd21093551e58c834f0f099e2 (diff)
downloadpython-fastimport-git-ee90b2a6afeebe24da17f5545eda7f0676867cf4.tar.gz
make the tests work again on python2
Diffstat (limited to 'fastimport')
-rw-r--r--fastimport/commands.py9
-rw-r--r--fastimport/parser.py4
-rw-r--r--fastimport/processors/filter_processor.py14
-rw-r--r--fastimport/tests/__init__.py1
-rw-r--r--fastimport/tests/test_commands.py20
-rw-r--r--fastimport/tests/test_filter_processor.py6
-rw-r--r--fastimport/tests/test_parser.py55
7 files changed, 61 insertions, 48 deletions
diff --git a/fastimport/commands.py b/fastimport/commands.py
index 760df8a..575c304 100644
--- a/fastimport/commands.py
+++ b/fastimport/commands.py
@@ -20,8 +20,10 @@ a fast-import stream.
"""
from __future__ import division
from past.utils import old_div
+from past.builtins import basestring
from builtins import object
+
import stat
# There is a bug in git 1.5.4.3 and older by which unquoting a string consumes
@@ -418,7 +420,8 @@ def check_path(path):
"""
if path is None or path == '' or path[0] == "/":
raise ValueError("illegal path '%s'" % path)
- if type(path) != str:
+ if not isinstance(path, basestring):
+ import ipdb;ipdb.set_trace()
raise TypeError("illegale type for path '%r'" % path)
return path
@@ -453,10 +456,10 @@ def format_who_when(fields):
sep = ''
else:
sep = ' '
- if isinstance(name, str):
+ if isinstance(name, basestring):
name = name.encode('utf8')
email = fields[1]
- if isinstance(email, str):
+ if isinstance(email, basestring):
email = email.encode('utf8')
result = "%s%s<%s> %d %s" % (name, sep, email, fields[2], offset_str)
return result
diff --git a/fastimport/parser.py b/fastimport/parser.py
index fe59eef..f44c963 100644
--- a/fastimport/parser.py
+++ b/fastimport/parser.py
@@ -158,10 +158,12 @@ The grammar is:
not_lf ::= # Any byte that is not ASCII newline (LF);
"""
from __future__ import print_function
+from __future__ import unicode_literals
from future import standard_library
standard_library.install_aliases()
from builtins import map
from builtins import object
+from builtins import str
import collections
@@ -622,6 +624,8 @@ class ImportParser(LineBasedParser):
def _unquote_c_string(s):
"""replace C-style escape sequences (\n, \", etc.) with real chars."""
# HACK: Python strings are close enough
+ #s = str(s)
+ #import ipdb;ipdb.set_trace()
return s.decode('string_escape', 'replace')
Authorship = collections.namedtuple('Authorship', 'name email timestamp timezone')
diff --git a/fastimport/processors/filter_processor.py b/fastimport/processors/filter_processor.py
index 5353b58..eaf7685 100644
--- a/fastimport/processors/filter_processor.py
+++ b/fastimport/processors/filter_processor.py
@@ -16,7 +16,7 @@
"""Import processor that filters the input (and doesn't import)."""
from future import standard_library
standard_library.install_aliases()
-
+from builtins import str as _text
from fastimport import (
commands,
@@ -161,13 +161,13 @@ class FilterProcessor(processor.ImportProcessor):
def _print_command(self, cmd):
"""Wrapper to avoid adding unnecessary blank lines."""
text = repr(cmd)
- self.outf.write(text)
- if not text.endswith("\n"):
- self.outf.write("\n")
+ self.outf.write(_text(text))
+ if not text.endswith(u"\n"):
+ self.outf.write(u"\n")
def _filter_filecommands(self, filecmd_iter):
"""Return the filecommands filtered by includes & excludes.
-
+
:return: a list of FileCommand objects
"""
if self.includes is None and self.excludes is None:
@@ -244,7 +244,7 @@ class FilterProcessor(processor.ImportProcessor):
def _convert_rename(self, fc):
"""Convert a FileRenameCommand into a new FileCommand.
-
+
:return: None if the rename is being ignored, otherwise a
new FileCommand based on the whether the old and new paths
are inside or outside of the interesting locations.
@@ -275,7 +275,7 @@ class FilterProcessor(processor.ImportProcessor):
def _convert_copy(self, fc):
"""Convert a FileCopyCommand into a new FileCommand.
-
+
:return: None if the copy is being ignored, otherwise a
new FileCommand based on the whether the source and destination
paths are inside or outside of the interesting locations.
diff --git a/fastimport/tests/__init__.py b/fastimport/tests/__init__.py
index 1d3a09e..ae5acb7 100644
--- a/fastimport/tests/__init__.py
+++ b/fastimport/tests/__init__.py
@@ -34,4 +34,5 @@ def test_suite():
loader = unittest.TestLoader()
suite = loader.loadTestsFromNames(module_names)
result.addTests(suite)
+
return result
diff --git a/fastimport/tests/test_commands.py b/fastimport/tests/test_commands.py
index 45d2a00..2139f8c 100644
--- a/fastimport/tests/test_commands.py
+++ b/fastimport/tests/test_commands.py
@@ -17,7 +17,6 @@
from future import standard_library
standard_library.install_aliases()
from builtins import map
-
from unittest import TestCase
from fastimport import (
@@ -66,14 +65,17 @@ class TestCommitDisplay(TestCase):
committer = (name, 'test@example.com', 1234567890, -6 * 3600)
c = commands.CommitCommand("refs/heads/master", "bbb", None, committer,
"release v1.0", ":aaa", None, None)
- self.assertEqual(
- "commit refs/heads/master\n"
- "mark :bbb\n"
- "committer %s <test@example.com> 1234567890 -0600\n"
- "data 12\n"
- "release v1.0\n"
- "from :aaa" % (name_utf8,),
- repr(c))
+ try:
+ self.assertEqual(
+ "commit refs/heads/master\n"
+ "mark :bbb\n"
+ "committer %s <test@example.com> 1234567890 -0600\n"
+ "data 12\n"
+ "release v1.0\n"
+ "from :aaa" % (name_utf8,),
+ repr(c))
+ except UnicodeEncodeError:
+ import ipdb;ipdb.set_trace()
def test_commit_no_mark(self):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
diff --git a/fastimport/tests/test_filter_processor.py b/fastimport/tests/test_filter_processor.py
index 7169499..153c05f 100644
--- a/fastimport/tests/test_filter_processor.py
+++ b/fastimport/tests/test_filter_processor.py
@@ -14,8 +14,10 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""Test FilterProcessor"""
+from __future__ import unicode_literals
from future import standard_library
standard_library.install_aliases()
+from builtins import str
from io import StringIO
@@ -937,7 +939,7 @@ M 644 :99 data/DATA2
"""
class TestSquashEmptyCommitsFlag(TestCaseWithFiltering):
-
+
def test_squash_empty_commit(self):
params = {'include_paths': None, 'exclude_paths': None}
self.assertFiltering(_SAMPLE_EMPTY_COMMIT, params, \
@@ -1072,7 +1074,7 @@ merge :1001
M 644 :99 data/DATA2
"""
)
-
+
def test_with_directory_includes(self):
params = {'include_paths': ['data/'],
'exclude_paths': None,
diff --git a/fastimport/tests/test_parser.py b/fastimport/tests/test_parser.py
index 79f293b..73bfeb0 100644
--- a/fastimport/tests/test_parser.py
+++ b/fastimport/tests/test_parser.py
@@ -16,6 +16,7 @@
"""Test the Import parsing"""
from future import standard_library
standard_library.install_aliases()
+from builtins import str as _text
import io
import time
@@ -31,7 +32,7 @@ from fastimport import (
class TestLineBasedParser(unittest.TestCase):
def test_push_line(self):
- s = io.StringIO("foo\nbar\nbaz\n")
+ s = io.StringIO(u"foo\nbar\nbaz\n")
p = parser.LineBasedParser(s)
self.assertEqual('foo', p.next_line())
self.assertEqual('bar', p.next_line())
@@ -41,7 +42,7 @@ class TestLineBasedParser(unittest.TestCase):
self.assertEqual(None, p.next_line())
def test_read_bytes(self):
- s = io.StringIO("foo\nbar\nbaz\n")
+ s = io.StringIO(u"foo\nbar\nbaz\n")
p = parser.LineBasedParser(s)
self.assertEqual('fo', p.read_bytes(2))
self.assertEqual('o\nb', p.read_bytes(3))
@@ -55,7 +56,7 @@ class TestLineBasedParser(unittest.TestCase):
def test_read_until(self):
# TODO
return
- s = io.StringIO("foo\nbar\nbaz\nabc\ndef\nghi\n")
+ s = io.StringIO(u"foo\nbar\nbaz\nabc\ndef\nghi\n")
p = parser.LineBasedParser(s)
self.assertEqual('foo\nbar', p.read_until('baz'))
self.assertEqual('abc', p.next_line())
@@ -155,7 +156,7 @@ class TestImportParser(unittest.TestCase):
del self.fake_time
def test_iter_commands(self):
- s = io.StringIO(_sample_import_text)
+ s = io.StringIO(_text(_sample_import_text))
p = parser.ImportParser(s)
result = []
for cmd in p.iter_commands():
@@ -273,30 +274,30 @@ class TestImportParser(unittest.TestCase):
self.assertEqual('donald@duck.org', cmd.more_authors[1][1])
def test_done_feature_missing_done(self):
- s = io.StringIO("""feature done
+ s = io.StringIO(u"""feature done
""")
p = parser.ImportParser(s)
cmds = p.iter_commands()
- self.assertEquals("feature", cmds.next().name)
- self.assertRaises(errors.PrematureEndOfStream, cmds.__next__)
+ self.assertEqual("feature", next(cmds).name)
+ self.assertRaises(errors.PrematureEndOfStream, lambda: next(cmds))
def test_done_with_feature(self):
- s = io.StringIO("""feature done
+ s = io.StringIO(u"""feature done
done
more data
""")
p = parser.ImportParser(s)
cmds = p.iter_commands()
- self.assertEquals("feature", cmds.next().name)
- self.assertRaises(StopIteration, cmds.__next__)
+ self.assertEqual("feature", next(cmds).name)
+ self.assertRaises(StopIteration, lambda: next(cmds))
def test_done_without_feature(self):
- s = io.StringIO("""done
+ s = io.StringIO(u"""done
more data
""")
p = parser.ImportParser(s)
cmds = p.iter_commands()
- self.assertEquals([], list(cmds))
+ self.assertEqual([], list(cmds))
class TestStringParsing(unittest.TestCase):
@@ -323,11 +324,11 @@ class TestTagParsing(unittest.TestCase):
def test_tagger_with_email(self):
p = parser.ImportParser(io.StringIO(
- "tag refs/tags/v1.0\n"
- "from :xxx\n"
- "tagger Joe Wong <joe@example.com> 1234567890 -0600\n"
- "data 11\n"
- "create v1.0"))
+ u"tag refs/tags/v1.0\n"
+ u"from :xxx\n"
+ u"tagger Joe Wong <joe@example.com> 1234567890 -0600\n"
+ u"data 11\n"
+ u"create v1.0"))
cmds = list(p.iter_commands())
self.assertEquals(1, len(cmds))
self.assertTrue(isinstance(cmds[0], commands.TagCommand))
@@ -336,20 +337,20 @@ class TestTagParsing(unittest.TestCase):
def test_tagger_no_email_strict(self):
p = parser.ImportParser(io.StringIO(
- "tag refs/tags/v1.0\n"
- "from :xxx\n"
- "tagger Joe Wong\n"
- "data 11\n"
- "create v1.0"))
+ u"tag refs/tags/v1.0\n"
+ u"from :xxx\n"
+ u"tagger Joe Wong\n"
+ u"data 11\n"
+ u"create v1.0"))
self.assertRaises(errors.BadFormat, list, p.iter_commands())
def test_tagger_no_email_not_strict(self):
p = parser.ImportParser(io.StringIO(
- "tag refs/tags/v1.0\n"
- "from :xxx\n"
- "tagger Joe Wong\n"
- "data 11\n"
- "create v1.0"), strict=False)
+ u"tag refs/tags/v1.0\n"
+ u"from :xxx\n"
+ u"tagger Joe Wong\n"
+ u"data 11\n"
+ u"create v1.0"), strict=False)
cmds = list(p.iter_commands())
self.assertEquals(1, len(cmds))
self.assertTrue(isinstance(cmds[0], commands.TagCommand))