summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@jelmer.uk>2019-12-01 16:06:43 +0000
committerJelmer Vernooij <jelmer@jelmer.uk>2019-12-01 16:06:43 +0000
commitcf8a7f49db9df39af8f0b8ca17b2546a447ffabd (patch)
tree05c24c0cda59cf1466e824262e7c637db7760236
parentbca03bde748f9d106d7f762b509ab3888ddbce80 (diff)
downloadpython-fastimport-git-cf8a7f49db9df39af8f0b8ca17b2546a447ffabd.tar.gz
Fix PEP8 formatting.
-rw-r--r--.travis.yml3
-rw-r--r--fastimport/commands.py45
-rw-r--r--fastimport/errors.py15
-rw-r--r--fastimport/helpers.py26
-rw-r--r--fastimport/parser.py64
-rw-r--r--fastimport/processors/filter_processor.py26
-rw-r--r--fastimport/processors/info_processor.py46
-rw-r--r--fastimport/processors/query_processor.py3
-rw-r--r--fastimport/reftracker.py5
-rw-r--r--fastimport/tests/test_commands.py74
-rw-r--r--fastimport/tests/test_dates.py1
-rw-r--r--fastimport/tests/test_errors.py27
-rw-r--r--fastimport/tests/test_filter_processor.py179
-rw-r--r--fastimport/tests/test_helpers.py3
-rw-r--r--fastimport/tests/test_info_processor.py1
-rw-r--r--fastimport/tests/test_parser.py23
-rwxr-xr-xsetup.py3
17 files changed, 314 insertions, 230 deletions
diff --git a/.travis.yml b/.travis.yml
index 675be6b..b4a5642 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,5 +8,6 @@ python:
- "3.8"
- "pypy"
install:
- - pip install unittest2 future
+ - pip install unittest2 future flake8
+ - flake8
script: python -m unittest2.__main__ fastimport.tests.test_suite
diff --git a/fastimport/commands.py b/fastimport/commands.py
index 7f29599..f2b44fb 100644
--- a/fastimport/commands.py
+++ b/fastimport/commands.py
@@ -43,9 +43,9 @@ GIT_FAST_IMPORT_NEEDS_EXTRA_SPACE_AFTER_QUOTE = False
# Lists of command names
COMMAND_NAMES = [b'blob', b'checkpoint', b'commit', b'feature', b'progress',
- b'reset', b'tag']
+ b'reset', b'tag']
FILE_COMMAND_NAMES = [b'filemodify', b'filedelete', b'filecopy', b'filerename',
- b'filedeleteall']
+ b'filedeleteall']
# Feature names
MULTIPLE_AUTHORS_FEATURE = b'multiple-authors'
@@ -147,7 +147,8 @@ class CheckpointCommand(ImportCommand):
class CommitCommand(ImportCommand):
def __init__(self, ref, mark, author, committer, message, from_,
- merges, file_iter, lineno=0, more_authors=None, properties=None):
+ merges, file_iter, lineno=0, more_authors=None,
+ properties=None):
ImportCommand.__init__(self, b'commit')
self.ref = ref
self.mark = mark
@@ -188,7 +189,6 @@ class CommitCommand(ImportCommand):
def __bytes__(self):
return self.to_string(include_file_contents=True)
-
def to_string(self, use_features=True, include_file_contents=False):
"""
@todo the name to_string is ambiguous since the method actually
@@ -224,8 +224,8 @@ class CommitCommand(ImportCommand):
if self.merges is None:
merge_lines = b''
else:
- merge_lines = b''.join([b'\nmerge ' + m
- for m in self.merges])
+ merge_lines = b''.join(
+ [b'\nmerge ' + m for m in self.merges])
if use_features and self.properties:
property_lines = []
for name in sorted(self.properties):
@@ -238,11 +238,11 @@ class CommitCommand(ImportCommand):
filecommands = b''
else:
if include_file_contents:
- filecommands = b''.join([b'\n' + repr_bytes(c)
- for c in self.iter_files()])
+ filecommands = b''.join(
+ [b'\n' + repr_bytes(c) for c in self.iter_files()])
else:
- filecommands = b''.join([b'\n' + str(c)
- for c in self.iter_files()])
+ filecommands = b''.join(
+ [b'\n' + str(c) for c in self.iter_files()])
return b''.join([
b'commit ',
self.ref,
@@ -390,7 +390,9 @@ class FileModifyCommand(FileCommand):
elif self.dataref is None:
dataref = b'inline'
if include_file_contents:
- datastr = ('\ndata %d\n' % len(self.data)).encode('ascii') + self.data
+ datastr = (
+ ('\ndata %d\n' % len(self.data)).encode('ascii') +
+ self.data)
else:
dataref = self.dataref
path = format_path(self.path)
@@ -417,9 +419,9 @@ class FileCopyCommand(FileCommand):
self.dest_path = check_path(dest_path)
def __bytes__(self):
- return b' '.join([b'C',
- format_path(self.src_path, quote_spaces=True),
- format_path(self.dest_path)])
+ return b' '.join(
+ [b'C', format_path(self.src_path, quote_spaces=True),
+ format_path(self.dest_path)])
class FileRenameCommand(FileCommand):
@@ -456,7 +458,7 @@ class NoteModifyCommand(FileCommand):
def __bytes__(self):
return (b'N inline :' + self.from_ +
- ('\ndata %d\n'% len(self.data)).encode('ascii') + self.data)
+ ('\ndata %d\n' % len(self.data)).encode('ascii') + self.data)
def check_path(path):
@@ -491,7 +493,7 @@ def format_path(p, quote_spaces=False):
def format_who_when(fields):
- """Format a tuple of name,email,secs-since-epoch,utc-offset-secs as a string."""
+ """Format tuple of name,email,secs-since-epoch,utc-offset-secs as bytes."""
offset = fields[3]
if offset < 0:
offset_sign = b'-'
@@ -500,7 +502,9 @@ def format_who_when(fields):
offset_sign = b'+'
offset_hours = offset // 3600
offset_minutes = offset // 60 - offset_hours * 60
- offset_str = offset_sign + ('%02d%02d' % (offset_hours, offset_minutes)).encode('ascii')
+ offset_str = (
+ offset_sign +
+ ('%02d%02d' % (offset_hours, offset_minutes)).encode('ascii'))
name = fields[0]
if name == b'':
@@ -514,7 +518,9 @@ def format_who_when(fields):
email = utf8_bytes_string(email)
- return b''.join((name, sep, b'<', email, b'> ', ("%d" % fields[2]).encode('ascii'), b' ', offset_str))
+ return b''.join(
+ (name, sep, b'<', email, b'> ',
+ ("%d" % fields[2]).encode('ascii'), b' ', offset_str))
def format_property(name, value):
@@ -525,6 +531,7 @@ def format_property(name, value):
result = b'property ' + utf8_name
if value is not None:
utf8_value = utf8_bytes_string(value)
- result += b' ' + ('%d' % len(utf8_value)).encode('ascii') + b' ' + utf8_value
+ result += (b' ' + ('%d' % len(utf8_value)).encode('ascii') +
+ b' ' + utf8_value)
return result
diff --git a/fastimport/errors.py b/fastimport/errors.py
index 7555628..723f294 100644
--- a/fastimport/errors.py
+++ b/fastimport/errors.py
@@ -18,7 +18,6 @@
# Prefix to messages to show location information
_LOCATION_FMT = "line %(lineno)d: "
-# ImportError is heavily based on BzrError
class ImportError(Exception):
"""The base exception class for all import processing exceptions."""
@@ -41,7 +40,7 @@ class MissingBytes(ParsingError):
"""Raised when EOF encountered while expecting to find more bytes."""
_fmt = (_LOCATION_FMT + "Unexpected EOF - expected %(expected)d bytes,"
- " found %(found)d")
+ " found %(found)d")
def __init__(self, lineno, expected, found):
self.expected = expected
@@ -53,7 +52,7 @@ class MissingTerminator(ParsingError):
"""Raised when EOF encountered while expecting to find a terminator."""
_fmt = (_LOCATION_FMT +
- "Unexpected EOF - expected '%(terminator)s' terminator")
+ "Unexpected EOF - expected '%(terminator)s' terminator")
def __init__(self, lineno, terminator):
self.terminator = terminator
@@ -85,7 +84,7 @@ class BadFormat(ParsingError):
"""Raised when a section is formatted incorrectly."""
_fmt = (_LOCATION_FMT + "Bad format for section %(section)s in "
- "command %(cmd)s: found '%(text)s'")
+ "command %(cmd)s: found '%(text)s'")
def __init__(self, lineno, cmd, section, text):
self.cmd = cmd
@@ -98,7 +97,7 @@ class InvalidTimezone(ParsingError):
"""Raised when converting a string timezone to a seconds offset."""
_fmt = (_LOCATION_FMT +
- "Timezone %(timezone)r could not be converted.%(reason)s")
+ "Timezone %(timezone)r could not be converted.%(reason)s")
def __init__(self, lineno, timezone, reason=None):
self.timezone = timezone
@@ -153,7 +152,7 @@ class BadRepositorySize(ImportError):
"""Raised when the repository has an incorrect number of revisions."""
_fmt = ("Bad repository size - %(found)d revisions found, "
- "%(expected)d expected")
+ "%(expected)d expected")
def __init__(self, expected, found):
self.expected = expected
@@ -165,7 +164,7 @@ class BadRestart(ImportError):
"""Raised when the import stream and id-map do not match up."""
_fmt = ("Bad restart - attempted to skip commit %(commit_id)s "
- "but matching revision-id is unknown")
+ "but matching revision-id is unknown")
def __init__(self, commit_id):
self.commit_id = commit_id
@@ -176,7 +175,7 @@ class UnknownFeature(ImportError):
"""Raised when an unknown feature is given in the input stream."""
_fmt = ("Unknown feature '%(feature)s' - try a later importer or "
- "an earlier data format")
+ "an earlier data format")
def __init__(self, feature):
self.feature = feature
diff --git a/fastimport/helpers.py b/fastimport/helpers.py
index 67072be..e252d09 100644
--- a/fastimport/helpers.py
+++ b/fastimport/helpers.py
@@ -19,15 +19,18 @@ import sys
def _common_path_and_rest(l1, l2, common=[]):
# From http://code.activestate.com/recipes/208993/
- if len(l1) < 1: return (common, l1, l2)
- if len(l2) < 1: return (common, l1, l2)
- if l1[0] != l2[0]: return (common, l1, l2)
+ if len(l1) < 1:
+ return (common, l1, l2)
+ if len(l2) < 1:
+ return (common, l1, l2)
+ if l1[0] != l2[0]:
+ return (common, l1, l2)
return _common_path_and_rest(
l1[1:],
l2[1:],
common + [
- l1[0:1] # return a byte string in python 3 unlike l1[0] that
- # would return an integer.
+ l1[0:1] # return a byte string in python 3 unlike l1[0] that
+ # would return an integer.
]
)
@@ -45,6 +48,7 @@ def common_directory(paths):
otherwise the common directory with a trailing / is returned.
"""
import posixpath
+
def get_dir_with_slash(path):
if path == b'' or path.endswith(b'/'):
return path
@@ -145,7 +149,7 @@ class newobject(object):
s = type(self).__str__(self)
else:
s = str(self)
- if isinstance(s, unicode):
+ if isinstance(s, unicode): # noqa: F821
return s
else:
return s.decode('utf-8')
@@ -177,8 +181,9 @@ class newobject(object):
# d = {}
# for k, v in iterable:
# d[k] = v
- # dict(**kwargs) -> new dictionary initialized with the name=value pairs
- # in the keyword argument list. For example: dict(one=1, two=2)
+ # dict(**kwargs) -> new dictionary initialized with the name=value
+ # pairs in the keyword argument list.
+ # For example: dict(one=1, two=2)
# """
# if len(args) == 0:
@@ -216,7 +221,7 @@ def binary_stream(stream):
def invert_dictset(d):
- """Invert a dictionary with keys matching a set of values, turned into lists."""
+ """Invert a dict with keys matching a set of values, turned into lists."""
# Based on recipe from ASPN
result = {}
for k, c in d.items():
@@ -260,6 +265,3 @@ def get_source_stream(source):
else:
stream = open(source, "rb")
return stream
-
-
-
diff --git a/fastimport/parser.py b/fastimport/parser.py
index 87671ab..5e399be 100644
--- a/fastimport/parser.py
+++ b/fastimport/parser.py
@@ -175,8 +175,6 @@ from fastimport.helpers import (
)
-## Stream parsing ##
-
class LineBasedParser(object):
def __init__(self, input_stream):
@@ -265,7 +263,7 @@ _WHO_RE = re.compile(br'([^<]*)<(.*)>')
class ImportParser(LineBasedParser):
def __init__(self, input_stream, verbose=False, output=sys.stdout,
- user_mapper=None, strict=True):
+ user_mapper=None, strict=True):
"""A Parser of import commands.
:param input_stream: the file-like object to read from
@@ -356,7 +354,7 @@ class ImportParser(LineBasedParser):
def _parse_commit(self, ref):
"""Parse a commit command."""
- lineno = self.lineno
+ lineno = self.lineno
mark = self._get_mark_if_any()
author = self._get_user_info(b'commit', b'author', False)
more_authors = []
@@ -388,7 +386,8 @@ class ImportParser(LineBasedParser):
properties[name] = value
else:
break
- return commands.CommitCommand(ref, mark, author, committer, message,
+ return commands.CommitCommand(
+ ref, mark, author, committer, message,
from_, merges, list(self.iter_file_commands()), lineno=lineno,
more_authors=more_authors, properties=properties)
@@ -418,8 +417,8 @@ class ImportParser(LineBasedParser):
else:
dataref = params[1]
data = None
- return commands.FileModifyCommand(path, mode, dataref,
- data)
+ return commands.FileModifyCommand(
+ path, mode, dataref, data)
def _parse_reset(self, ref):
"""Parse a reset command."""
@@ -429,8 +428,8 @@ class ImportParser(LineBasedParser):
def _parse_tag(self, name):
"""Parse a tag command."""
from_ = self._get_from(b'tag')
- tagger = self._get_user_info(b'tag', b'tagger',
- accept_just_who=True)
+ tagger = self._get_user_info(
+ b'tag', b'tagger', accept_just_who=True)
message = self._get_data(b'tag', b'message')
return commands.TagCommand(name, from_, tagger, message)
@@ -479,11 +478,12 @@ class ImportParser(LineBasedParser):
return None
def _get_user_info(self, cmd, section, required=True,
- accept_just_who=False):
+ accept_just_who=False):
"""Parse a user section."""
line = self.next_line()
if line.startswith(section + b' '):
- return self._who_when(line[len(section + b' '):], cmd, section,
+ return self._who_when(
+ line[len(section + b' '):], cmd, section,
accept_just_who=accept_just_who)
elif required:
self.abort(errors.MissingSection, cmd, section)
@@ -626,8 +626,8 @@ ESCAPE_SEQUENCE_BYTES_RE = re.compile(br'''
| \\[0-7]{1,3} # Octal escapes
| \\N\{[^}]+\} # Unicode characters by name
| \\[\\'"abfnrtv] # Single-character escapes
- )''', re.VERBOSE
-)
+ )''', re.VERBOSE)
+
ESCAPE_SEQUENCE_RE = re.compile(r'''
( \\U........
@@ -636,24 +636,24 @@ ESCAPE_SEQUENCE_RE = re.compile(r'''
| \\[0-7]{1,3}
| \\N\{[^}]+\}
| \\[\\'"abfnrtv]
- )''', re.UNICODE | re.VERBOSE
-)
-
-def _unquote_c_string(s):
- """replace C-style escape sequences (\n, \", etc.) with real chars."""
-
- # doing a s.encode('utf-8').decode('unicode_escape') can return an
- # incorrect output with unicode string (both in py2 and py3) the safest way
- # is to match the escape sequences and decoding them alone.
- def decode_match(match):
- return utf8_bytes_string(
- codecs.decode(match.group(0), 'unicode-escape')
- )
+ )''', re.UNICODE | re.VERBOSE)
- if sys.version_info[0] >= 3 and isinstance(s, bytes):
- return ESCAPE_SEQUENCE_BYTES_RE.sub(decode_match, s)
- else:
- return ESCAPE_SEQUENCE_RE.sub(decode_match, s)
-
-Authorship = collections.namedtuple('Authorship', 'name email timestamp timezone')
+def _unquote_c_string(s):
+ """replace C-style escape sequences (\n, \", etc.) with real chars."""
+ # doing a s.encode('utf-8').decode('unicode_escape') can return an
+ # incorrect output with unicode string (both in py2 and py3) the safest way
+ # is to match the escape sequences and decoding them alone.
+ def decode_match(match):
+ return utf8_bytes_string(
+ codecs.decode(match.group(0), 'unicode-escape')
+ )
+
+ if sys.version_info[0] >= 3 and isinstance(s, bytes):
+ return ESCAPE_SEQUENCE_BYTES_RE.sub(decode_match, s)
+ else:
+ return ESCAPE_SEQUENCE_RE.sub(decode_match, s)
+
+
+Authorship = collections.namedtuple(
+ 'Authorship', 'name email timestamp timezone')
diff --git a/fastimport/processors/filter_processor.py b/fastimport/processors/filter_processor.py
index 0ca4472..6c8c967 100644
--- a/fastimport/processors/filter_processor.py
+++ b/fastimport/processors/filter_processor.py
@@ -98,7 +98,7 @@ class FilterProcessor(processor.ImportProcessor):
if interesting_filecmds or not self.squash_empty_commits:
# If all we have is a single deleteall, skip this commit
if len(interesting_filecmds) == 1 and isinstance(
- interesting_filecmds[0], commands.FileDeleteAllCommand):
+ interesting_filecmds[0], commands.FileDeleteAllCommand):
pass
else:
# Remember just the interesting file commands
@@ -109,7 +109,7 @@ class FilterProcessor(processor.ImportProcessor):
for fc in interesting_filecmds:
if isinstance(fc, commands.FileModifyCommand):
if (fc.dataref is not None and
- not stat.S_ISDIR(fc.mode)):
+ not stat.S_ISDIR(fc.mode)):
self.referenced_blobs.append(fc.dataref)
# Update from and merges to refer to commits in the output
@@ -149,7 +149,8 @@ class FilterProcessor(processor.ImportProcessor):
"""Process a FeatureCommand."""
feature = cmd.feature_name
if feature not in commands.FEATURE_NAMES:
- self.warning("feature %s is not supported - parsing may fail"
+ self.warning(
+ "feature %s is not supported - parsing may fail"
% (feature,))
# These always pass through
self.keep = True
@@ -173,7 +174,7 @@ class FilterProcessor(processor.ImportProcessor):
result = []
for fc in filecmd_iter():
if (isinstance(fc, commands.FileModifyCommand) or
- isinstance(fc, commands.FileDeleteCommand)):
+ isinstance(fc, commands.FileDeleteCommand)):
if self._path_to_be_kept(fc.path):
fc.path = self._adjust_for_new_root(fc.path)
else:
@@ -185,8 +186,9 @@ class FilterProcessor(processor.ImportProcessor):
elif isinstance(fc, commands.FileCopyCommand):
fc = self._convert_copy(fc)
else:
- self.warning("cannot handle FileCommands of class %s - ignoring",
- fc.__class__)
+ self.warning(
+ "cannot handle FileCommands of class %s - ignoring",
+ fc.__class__)
continue
if fc is not None:
result.append(fc)
@@ -194,11 +196,13 @@ class FilterProcessor(processor.ImportProcessor):
def _path_to_be_kept(self, path):
"""Does the given path pass the filtering criteria?"""
- if self.excludes and (path in self.excludes
+ if self.excludes and (
+ path in self.excludes
or helpers.is_inside_any(self.excludes, path)):
return False
if self.includes:
- return (path in self.includes
+ return (
+ path in self.includes
or helpers.is_inside_any(self.includes, path))
return True
@@ -265,7 +269,8 @@ class FilterProcessor(processor.ImportProcessor):
# to. Maybe fast-import-info needs to be extended to
# remember all renames and a config file can be passed
# into here ala fast-import?
- self.warning("cannot turn rename of %s into an add of %s yet" %
+ self.warning(
+ "cannot turn rename of %s into an add of %s yet" %
(old, new))
return None
@@ -295,6 +300,7 @@ class FilterProcessor(processor.ImportProcessor):
# to. Maybe fast-import-info needs to be extended to
# remember all copies and a config file can be passed
# into here ala fast-import?
- self.warning("cannot turn copy of %s into an add of %s yet" %
+ self.warning(
+ "cannot turn copy of %s into an add of %s yet" %
(src, dest))
return None
diff --git a/fastimport/processors/info_processor.py b/fastimport/processors/info_processor.py
index 28c7300..13346df 100644
--- a/fastimport/processors/info_processor.py
+++ b/fastimport/processors/info_processor.py
@@ -43,8 +43,8 @@ class InfoProcessor(processor.ImportProcessor):
"""
def __init__(self, params=None, verbose=0, outf=None):
- processor.ImportProcessor.__init__(self, params, verbose,
- outf=outf)
+ processor.ImportProcessor.__init__(
+ self, params, verbose, outf=outf)
def pre_process(self):
# Init statistics
@@ -79,10 +79,13 @@ class InfoProcessor(processor.ImportProcessor):
# Dump statistics
cmd_names = commands.COMMAND_NAMES
fc_names = commands.FILE_COMMAND_NAMES
- self._dump_stats_group("Command counts",
+ self._dump_stats_group(
+ "Command counts",
[(c.decode('utf-8'), self.cmd_counts[c]) for c in cmd_names], str)
- self._dump_stats_group("File command counts",
- [(c.decode('utf-8'), self.file_cmd_counts[c]) for c in fc_names], str)
+ self._dump_stats_group(
+ "File command counts",
+ [(c.decode('utf-8'), self.file_cmd_counts[c]) for c in fc_names],
+ str)
# Commit stats
if self.cmd_counts[b'commit']:
@@ -100,7 +103,8 @@ class InfoProcessor(processor.ImportProcessor):
'blobs referenced by SHA': self.sha_blob_references,
}
self._dump_stats_group("Parent counts", p_items, str)
- self._dump_stats_group("Commit analysis", sorted(flags.items()), _found)
+ self._dump_stats_group(
+ "Commit analysis", sorted(flags.items()), _found)
heads = invert_dictset(self.reftracker.heads)
self._dump_stats_group(
"Head analysis",
@@ -114,10 +118,12 @@ class InfoProcessor(processor.ImportProcessor):
# (verbose=2) is specified. The output here for mysql's data can't
# be parsed currently so this bit of code needs more work anyhow ..
if self.verbose >= 2:
- self._dump_stats_group("Rename old paths",
+ self._dump_stats_group(
+ "Rename old paths",
self.rename_old_paths.items(), len,
_iterable_as_config_list)
- self._dump_stats_group("Copy source paths",
+ self._dump_stats_group(
+ "Copy source paths",
self.copy_source_paths.items(), len,
_iterable_as_config_list)
@@ -126,12 +132,14 @@ class InfoProcessor(processor.ImportProcessor):
# In verbose mode, don't list every blob used
if self.verbose:
del self.blobs['used']
- self._dump_stats_group("Blob usage tracking",
+ self._dump_stats_group(
+ "Blob usage tracking",
self.blobs.items(), len, _iterable_as_config_list)
if self.blob_ref_counts:
blobs_by_count = invert_dict(self.blob_ref_counts)
blob_items = sorted(blobs_by_count.items())
- self._dump_stats_group("Blob reference counts",
+ self._dump_stats_group(
+ "Blob reference counts",
blob_items, len, _iterable_as_config_list)
# Other stats
@@ -142,9 +150,9 @@ class InfoProcessor(processor.ImportProcessor):
self._dump_stats_group("Reset analysis", reset_stats.items())
def _dump_stats_group(self, title, items, normal_formatter=None,
- verbose_formatter=None):
+ verbose_formatter=None):
"""Dump a statistics group.
-
+
In verbose mode, do so as a config file so
that other processors can load the information if they want to.
:param normal_formatter: the callable to apply to the value
@@ -210,9 +218,11 @@ class InfoProcessor(processor.ImportProcessor):
else:
self.sha_blob_references = True
elif isinstance(fc, commands.FileRenameCommand):
- self.rename_old_paths.setdefault(cmd.id, set()).add(fc.old_path)
+ self.rename_old_paths.setdefault(cmd.id, set()).add(
+ fc.old_path)
elif isinstance(fc, commands.FileCopyCommand):
- self.copy_source_paths.setdefault(cmd.id, set()).add(fc.src_path)
+ self.copy_source_paths.setdefault(cmd.id, set()).add(
+ fc.src_path)
# Track the heads
parents = self.reftracker.track_heads(cmd)
@@ -228,7 +238,6 @@ class InfoProcessor(processor.ImportProcessor):
# Remember the merges
if cmd.merges:
- #self.merges.setdefault(cmd.ref, set()).update(cmd.merges)
for merge in cmd.merges:
if merge in self.merges:
self.merges[merge] += 1
@@ -254,7 +263,8 @@ class InfoProcessor(processor.ImportProcessor):
self.cmd_counts[cmd.name] += 1
feature = cmd.feature_name
if feature not in commands.FEATURE_NAMES:
- self.warning("feature %s is not supported - parsing may fail"
+ self.warning(
+ "feature %s is not supported - parsing may fail"
% (feature,))
def _track_blob(self, mark):
@@ -270,13 +280,15 @@ class InfoProcessor(processor.ImportProcessor):
else:
self.blobs['unknown'].add(mark)
+
def _found(b):
"""Format a found boolean as a string."""
return ['no', 'found'][b]
+
def _iterable_as_config_list(s):
"""Format an iterable as a sequence of comma-separated strings.
-
+
To match what ConfigObj expects, a single item list has a trailing comma.
"""
items = sorted(s)
diff --git a/fastimport/processors/query_processor.py b/fastimport/processors/query_processor.py
index a40f2d6..0d40b48 100644
--- a/fastimport/processors/query_processor.py
+++ b/fastimport/processors/query_processor.py
@@ -94,5 +94,6 @@ class QueryProcessor(processor.ImportProcessor):
"""Process a FeatureCommand."""
feature = cmd.feature_name
if feature not in commands.FEATURE_NAMES:
- self.warning("feature %s is not supported - parsing may fail"
+ self.warning(
+ "feature %s is not supported - parsing may fail"
% (feature,))
diff --git a/fastimport/reftracker.py b/fastimport/reftracker.py
index 16a5e45..98a7b9f 100644
--- a/fastimport/reftracker.py
+++ b/fastimport/reftracker.py
@@ -22,7 +22,8 @@ from __future__ import absolute_import
class RefTracker(object):
def __init__(self):
- # Head tracking: last ref, last id per ref & map of commit ids to ref*s*
+ # Head tracking: last ref, last id per ref & map of commit ids to
+ # ref*s*
self.last_ref = None
self.last_ids = {}
self.heads = {}
@@ -64,5 +65,3 @@ class RefTracker(object):
self.heads.setdefault(cmd_id, set()).add(cmd_ref)
self.last_ids[cmd_ref] = cmd_id
self.last_ref = cmd_ref
-
-
diff --git a/fastimport/tests/test_commands.py b/fastimport/tests/test_commands.py
index ccae34a..8075661 100644
--- a/fastimport/tests/test_commands.py
+++ b/fastimport/tests/test_commands.py
@@ -50,7 +50,8 @@ 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,
+ 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"
@@ -75,7 +76,8 @@ class TestCommitDisplay(TestCase):
)
committer = (name, b'test@example.com', 1234567890, -6 * 3600)
- c = commands.CommitCommand(b'refs/heads/master', b'bbb', None, committer,
+ c = commands.CommitCommand(
+ b'refs/heads/master', b'bbb', None, committer,
b'release v1.0', b':aaa', None, None)
self.assertEqual(commit_utf8, repr_bytes(c))
@@ -83,8 +85,9 @@ class TestCommitDisplay(TestCase):
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)
+ 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"
@@ -96,7 +99,8 @@ class TestCommitDisplay(TestCase):
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,
+ 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"
@@ -110,7 +114,8 @@ class TestCommitDisplay(TestCase):
# user tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
author = (b'Sue Wong', b'sue@example.com', 1234565432, -6 * 3600)
committer = (b'Joe Wong', b'joe@example.com', 1234567890, -6 * 3600)
- c = commands.CommitCommand(b'refs/heads/master', b'bbb', author,
+ c = commands.CommitCommand(
+ b'refs/heads/master', b'bbb', author,
committer, b'release v1.0', b':aaa', None, None)
self.assertEqual(
b"commit refs/heads/master\n"
@@ -125,7 +130,8 @@ class TestCommitDisplay(TestCase):
def test_commit_with_merges(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"ddd", None, committer,
+ c = commands.CommitCommand(
+ b"refs/heads/master", b"ddd", None, committer,
b'release v1.0', b":aaa", [b':bbb', b':ccc'], None)
self.assertEqual(
b"commit refs/heads/master\n"
@@ -141,12 +147,13 @@ class TestCommitDisplay(TestCase):
def test_commit_with_filecommands(self):
file_cmds = iter([
commands.FileDeleteCommand(b'readme.txt'),
- commands.FileModifyCommand(b'NEWS', 0o100644, None,
- b'blah blah blah'),
+ commands.FileModifyCommand(
+ b'NEWS', 0o100644, None, b'blah blah blah'),
])
# 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,
+ c = commands.CommitCommand(
+ b'refs/heads/master', b'bbb', None, committer,
b'release v1.0', b':aaa', None, file_cmds)
self.assertEqual(
b"commit refs/heads/master\n"
@@ -169,7 +176,8 @@ class TestCommitDisplay(TestCase):
(b'Al Smith', b'al@example.com', 1234565432, -6 * 3600),
(b'Bill Jones', b'bill@example.com', 1234565432, -6 * 3600),
]
- c = commands.CommitCommand(b'refs/heads/master', b'bbb', author,
+ c = commands.CommitCommand(
+ b'refs/heads/master', b'bbb', author,
committer, b'release v1.0', b':aaa', None, None,
more_authors=more_authors)
self.assertEqual(
@@ -191,7 +199,8 @@ class TestCommitDisplay(TestCase):
u'greeting': u'hello',
u'planet': u'world',
}
- c = commands.CommitCommand(b'refs/heads/master', b'bbb', None,
+ c = commands.CommitCommand(
+ b'refs/heads/master', b'bbb', None,
committer, b'release v1.0', b':aaa', None, None,
properties=properties)
self.assertEqual(
@@ -212,7 +221,8 @@ class TestCommitDisplay(TestCase):
u'greeting': u'hello',
u'planet': u'world',
}
- c = commands.CommitCommand(b'refs/heads/master', 123, None,
+ c = commands.CommitCommand(
+ b'refs/heads/master', 123, None,
committer, b'release v1.0', b':aaa', None, None,
properties=properties)
self.assertEqual(
@@ -226,13 +236,15 @@ class TestCommitDisplay(TestCase):
b"property planet 5 world",
repr_bytes(c))
+
class TestCommitCopy(TestCase):
def setUp(self):
super(TestCommitCopy, self).setUp()
file_cmds = iter([
commands.FileDeleteCommand(b'readme.txt'),
- commands.FileModifyCommand(b'NEWS', 0o100644, None, b'blah blah blah'),
+ commands.FileModifyCommand(
+ b'NEWS', 0o100644, None, b'blah blah blah'),
])
committer = (b'Joe Wong', b'joe@example.com', 1234567890, -6 * 3600)
@@ -256,6 +268,7 @@ class TestCommitCopy(TestCase):
def test_invalid_attribute(self):
self.assertRaises(TypeError, self.c.copy, invalid=True)
+
class TestFeatureDisplay(TestCase):
def test_feature(self):
@@ -290,7 +303,8 @@ class TestTagDisplay(TestCase):
def test_tag(self):
# tagger tuple is (name, email, secs-since-epoch, secs-offset-from-utc)
tagger = (b'Joe Wong', b'joe@example.com', 1234567890, -6 * 3600)
- c = commands.TagCommand(b'refs/tags/v1.0', b':xxx', tagger, b'create v1.0')
+ c = commands.TagCommand(
+ b'refs/tags/v1.0', b':xxx', tagger, b'create v1.0')
self.assertEqual(
b"tag refs/tags/v1.0\n"
b"from :xxx\n"
@@ -301,7 +315,8 @@ class TestTagDisplay(TestCase):
def test_tag_no_from(self):
tagger = (b'Joe Wong', b'joe@example.com', 1234567890, -6 * 3600)
- c = commands.TagCommand(b'refs/tags/v1.0', None, tagger, b'create v1.0')
+ c = commands.TagCommand(
+ b'refs/tags/v1.0', None, tagger, b'create v1.0')
self.assertEqual(
b"tag refs/tags/v1.0\n"
b"tagger Joe Wong <joe@example.com> 1234567890 -0600\n"
@@ -321,18 +336,21 @@ class TestFileModifyDisplay(TestCase):
self.assertEqual(b'M 755 :23 foo/bar', repr_bytes(c))
def test_filemodify_file_internal(self):
- c = commands.FileModifyCommand(b'foo/bar', 0o100644, None,
- b'hello world')
- self.assertEqual(b'M 644 inline foo/bar\ndata 11\nhello world', repr_bytes(c))
+ c = commands.FileModifyCommand(
+ b'foo/bar', 0o100644, None, b'hello world')
+ self.assertEqual(
+ b'M 644 inline foo/bar\ndata 11\nhello world', repr_bytes(c))
def test_filemodify_symlink(self):
c = commands.FileModifyCommand(b'foo/bar', 0o120000, None, b'baz')
- self.assertEqual(b'M 120000 inline foo/bar\ndata 3\nbaz', repr_bytes(c))
+ self.assertEqual(
+ b'M 120000 inline foo/bar\ndata 3\nbaz', repr_bytes(c))
def test_filemodify_treeref(self):
- c = commands.FileModifyCommand(b'tree-info', 0o160000,
- b'revision-id-info', None)
- self.assertEqual(b'M 160000 revision-id-info tree-info', repr_bytes(c))
+ c = commands.FileModifyCommand(
+ b'tree-info', 0o160000, b'revision-id-info', None)
+ self.assertEqual(
+ b'M 160000 revision-id-info tree-info', repr_bytes(c))
class TestFileDeleteDisplay(TestCase):
@@ -372,11 +390,13 @@ class TestFileDeleteAllDisplay(TestCase):
c = commands.FileDeleteAllCommand()
self.assertEqual(b'deleteall', repr_bytes(c))
+
class TestNotesDisplay(TestCase):
def test_noteonly(self):
c = commands.NoteModifyCommand(b'foo', b'A basic note')
- self.assertEqual(b'N inline :foo\ndata 12\nA basic note', repr_bytes(c))
+ self.assertEqual(
+ b'N inline :foo\ndata 12\nA basic note', repr_bytes(c))
def test_notecommit(self):
committer = (b'Ed Mund', b'ed@example.org', 1234565432, 0)
@@ -449,9 +469,11 @@ Test test
class TestPathChecking(TestCase):
def test_filemodify_path_checking(self):
- self.assertRaises(ValueError, commands.FileModifyCommand, b'',
+ self.assertRaises(
+ ValueError, commands.FileModifyCommand, b'',
0o100644, None, b'text')
- self.assertRaises(ValueError, commands.FileModifyCommand, None,
+ self.assertRaises(
+ ValueError, commands.FileModifyCommand, None,
0o100644, None, b'text')
def test_filedelete_path_checking(self):
diff --git a/fastimport/tests/test_dates.py b/fastimport/tests/test_dates.py
index f1ccd67..cc2617f 100644
--- a/fastimport/tests/test_dates.py
+++ b/fastimport/tests/test_dates.py
@@ -21,6 +21,7 @@ from fastimport import (
dates,
)
+
class ParseTzTests(TestCase):
def test_parse_tz_utc(self):
diff --git a/fastimport/tests/test_errors.py b/fastimport/tests/test_errors.py
index 4fc7dcd..895f783 100644
--- a/fastimport/tests/test_errors.py
+++ b/fastimport/tests/test_errors.py
@@ -25,27 +25,28 @@ class TestErrors(TestCase):
def test_MissingBytes(self):
e = errors.MissingBytes(99, 10, 8)
- self.assertEqual("line 99: Unexpected EOF - expected 10 bytes, found 8",
+ self.assertEqual(
+ "line 99: Unexpected EOF - expected 10 bytes, found 8",
str(e))
def test_MissingTerminator(self):
e = errors.MissingTerminator(99, '---')
- self.assertEqual("line 99: Unexpected EOF - expected '---' terminator",
+ self.assertEqual(
+ "line 99: Unexpected EOF - expected '---' terminator",
str(e))
def test_InvalidCommand(self):
e = errors.InvalidCommand(99, 'foo')
- self.assertEqual("line 99: Invalid command 'foo'",
- str(e))
+ self.assertEqual("line 99: Invalid command 'foo'", str(e))
def test_MissingSection(self):
e = errors.MissingSection(99, 'foo', 'bar')
- self.assertEqual("line 99: Command foo is missing section bar",
- str(e))
+ self.assertEqual("line 99: Command foo is missing section bar", str(e))
def test_BadFormat(self):
e = errors.BadFormat(99, 'foo', 'bar', 'xyz')
- self.assertEqual("line 99: Bad format for section bar in "
+ self.assertEqual(
+ "line 99: Bad format for section bar in "
"command foo: found 'xyz'",
str(e))
@@ -53,14 +54,15 @@ class TestErrors(TestCase):
e = errors.InvalidTimezone(99, 'aa:bb')
self.assertEqual('aa:bb', e.timezone)
self.assertEqual('', e.reason)
- self.assertEqual("line 99: Timezone 'aa:bb' could not be converted.",
+ self.assertEqual(
+ "line 99: Timezone 'aa:bb' could not be converted.",
str(e))
e = errors.InvalidTimezone(99, 'aa:bb', 'Non-numeric hours')
self.assertEqual('aa:bb', e.timezone)
self.assertEqual(' Non-numeric hours', e.reason)
- self.assertEqual("line 99: Timezone 'aa:bb' could not be converted."
- " Non-numeric hours",
- str(e))
+ self.assertEqual(
+ "line 99: Timezone 'aa:bb' could not be converted."
+ " Non-numeric hours", str(e))
def test_UnknownDateFormat(self):
e = errors.UnknownDateFormat('aaa')
@@ -72,5 +74,6 @@ class TestErrors(TestCase):
def test_UnknownFeature(self):
e = errors.UnknownFeature('aaa')
- self.assertEqual("Unknown feature 'aaa' - try a later importer or "
+ self.assertEqual(
+ "Unknown feature 'aaa' - try a later importer or "
"an earlier data format", str(e))
diff --git a/fastimport/tests/test_filter_processor.py b/fastimport/tests/test_filter_processor.py
index 809bdc8..7659db1 100644
--- a/fastimport/tests/test_filter_processor.py
+++ b/fastimport/tests/test_filter_processor.py
@@ -28,8 +28,8 @@ from fastimport.processors import (
# A sample input stream containing all (top level) import commands
-_SAMPLE_ALL = \
-b"""blob
+_SAMPLE_ALL = b"""\
+blob
mark :1
data 4
foo
@@ -56,8 +56,8 @@ release v0.1
# NEWS
# doc/README.txt
# doc/index.txt
-_SAMPLE_WITH_DIR = \
-b"""blob
+_SAMPLE_WITH_DIR = b"""\
+blob
mark :1
data 9
Welcome!
@@ -101,6 +101,7 @@ M 644 :3 doc/README.txt
M 644 :4 doc/index.txt
"""
+
class TestCaseWithFiltering(TestCase):
def assertFiltering(self, input_stream, params, expected):
@@ -114,6 +115,7 @@ class TestCaseWithFiltering(TestCase):
out = outf.getvalue()
self.assertEqual(expected, out)
+
class TestNoFiltering(TestCaseWithFiltering):
def test_params_not_given(self):
@@ -131,8 +133,8 @@ class TestIncludePaths(TestCaseWithFiltering):
# * only referenced blobs are retained
# * from clause is dropped from the first command
params = {b'include_paths': [b'NEWS']}
- self.assertFiltering(_SAMPLE_WITH_DIR, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_WITH_DIR, params, b"""\
+blob
mark :2
data 17
Life
@@ -152,8 +154,8 @@ M 644 :2 NEWS
# * new root: path is now index.txt, not doc/index.txt
# * other files changed in matching commits are excluded
params = {b'include_paths': [b'doc/index.txt']}
- self.assertFiltering(_SAMPLE_WITH_DIR, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_WITH_DIR, params, b"""\
+blob
mark :4
data 11
== Docs ==
@@ -170,8 +172,8 @@ M 644 :4 index.txt
# Additional things to note:
# * from updated to reference parents in the output
params = {b'include_paths': [b'doc/README.txt']}
- self.assertFiltering(_SAMPLE_WITH_DIR, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_WITH_DIR, params, b"""\
+blob
mark :1
data 9
Welcome!
@@ -198,8 +200,8 @@ M 644 :3 README.txt
def test_subdir(self):
params = {b'include_paths': [b'doc/']}
- self.assertFiltering(_SAMPLE_WITH_DIR, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_WITH_DIR, params, b"""\
+blob
mark :1
data 9
Welcome!
@@ -232,8 +234,8 @@ M 644 :4 index.txt
def test_multiple_files_in_subdir(self):
# The new root should be the subdrectory
params = {b'include_paths': [b'doc/README.txt', b'doc/index.txt']}
- self.assertFiltering(_SAMPLE_WITH_DIR, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_WITH_DIR, params, b"""\
+blob
mark :1
data 9
Welcome!
@@ -268,8 +270,8 @@ class TestExcludePaths(TestCaseWithFiltering):
def test_file_in_root(self):
params = {b'exclude_paths': [b'NEWS']}
- self.assertFiltering(_SAMPLE_WITH_DIR, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_WITH_DIR, params, b"""\
+blob
mark :1
data 9
Welcome!
@@ -301,8 +303,8 @@ M 644 :4 doc/index.txt
def test_file_in_subdir(self):
params = {b'exclude_paths': [b'doc/README.txt']}
- self.assertFiltering(_SAMPLE_WITH_DIR, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_WITH_DIR, params, b"""\
+blob
mark :2
data 17
Life
@@ -331,8 +333,8 @@ M 644 :4 doc/index.txt
def test_subdir(self):
params = {b'exclude_paths': [b'doc/']}
- self.assertFiltering(_SAMPLE_WITH_DIR, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_WITH_DIR, params, b"""\
+blob
mark :2
data 17
Life
@@ -349,8 +351,8 @@ M 644 :2 NEWS
def test_multple_files(self):
params = {b'exclude_paths': [b'doc/index.txt', b'NEWS']}
- self.assertFiltering(_SAMPLE_WITH_DIR, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_WITH_DIR, params, b"""\
+blob
mark :1
data 9
Welcome!
@@ -379,9 +381,11 @@ M 644 :3 doc/README.txt
class TestIncludeAndExcludePaths(TestCaseWithFiltering):
def test_included_dir_and_excluded_file(self):
- params = {b'include_paths': [b'doc/'], b'exclude_paths': [b'doc/index.txt']}
- self.assertFiltering(_SAMPLE_WITH_DIR, params, \
-b"""blob
+ params = {
+ b'include_paths': [b'doc/'],
+ b'exclude_paths': [b'doc/index.txt']}
+ self.assertFiltering(_SAMPLE_WITH_DIR, params, b"""\
+blob
mark :1
data 9
Welcome!
@@ -414,8 +418,8 @@ M 644 :3 README.txt
# doc/index.txt
#
# It then renames doc/README.txt => doc/README
-_SAMPLE_WITH_RENAME_INSIDE = _SAMPLE_WITH_DIR + \
-b"""commit refs/heads/master
+_SAMPLE_WITH_RENAME_INSIDE = _SAMPLE_WITH_DIR + b"""\
+commit refs/heads/master
mark :103
committer d <b@c> 1234798653 +0000
data 10
@@ -431,8 +435,8 @@ R doc/README.txt doc/README
# doc/index.txt
#
# It then renames doc/README.txt => README
-_SAMPLE_WITH_RENAME_TO_OUTSIDE = _SAMPLE_WITH_DIR + \
-b"""commit refs/heads/master
+_SAMPLE_WITH_RENAME_TO_OUTSIDE = _SAMPLE_WITH_DIR + b"""\
+commit refs/heads/master
mark :103
committer d <b@c> 1234798653 +0000
data 10
@@ -448,8 +452,8 @@ R doc/README.txt README
# doc/index.txt
#
# It then renames NEWS => doc/NEWS
-_SAMPLE_WITH_RENAME_TO_INSIDE = _SAMPLE_WITH_DIR + \
-b"""commit refs/heads/master
+_SAMPLE_WITH_RENAME_TO_INSIDE = _SAMPLE_WITH_DIR + b"""\
+commit refs/heads/master
mark :103
committer d <b@c> 1234798653 +0000
data 10
@@ -458,13 +462,14 @@ from :102
R NEWS doc/NEWS
"""
+
class TestIncludePathsWithRenames(TestCaseWithFiltering):
def test_rename_all_inside(self):
# These rename commands ought to be kept but adjusted for the new root
params = {b'include_paths': [b'doc/']}
- self.assertFiltering(_SAMPLE_WITH_RENAME_INSIDE, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_WITH_RENAME_INSIDE, params, b"""\
+blob
mark :1
data 9
Welcome!
@@ -504,8 +509,8 @@ R README.txt README
def test_rename_to_outside(self):
# These rename commands become deletes
params = {b'include_paths': [b'doc/']}
- self.assertFiltering(_SAMPLE_WITH_RENAME_TO_OUTSIDE, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_WITH_RENAME_TO_OUTSIDE, params, b"""\
+blob
mark :1
data 9
Welcome!
@@ -545,8 +550,8 @@ D README.txt
def test_rename_to_inside(self):
# This ought to create a new file but doesn't yet
params = {b'include_paths': [b'doc/']}
- self.assertFiltering(_SAMPLE_WITH_RENAME_TO_INSIDE, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_WITH_RENAME_TO_INSIDE, params, b"""\
+blob
mark :1
data 9
Welcome!
@@ -584,8 +589,8 @@ M 644 :4 index.txt
# doc/index.txt
#
# It then copies doc/README.txt => doc/README
-_SAMPLE_WITH_COPY_INSIDE = _SAMPLE_WITH_DIR + \
-b"""commit refs/heads/master
+_SAMPLE_WITH_COPY_INSIDE = _SAMPLE_WITH_DIR + b"""\
+commit refs/heads/master
mark :103
committer d <b@c> 1234798653 +0000
data 10
@@ -601,8 +606,8 @@ C doc/README.txt doc/README
# doc/index.txt
#
# It then copies doc/README.txt => README
-_SAMPLE_WITH_COPY_TO_OUTSIDE = _SAMPLE_WITH_DIR + \
-b"""commit refs/heads/master
+_SAMPLE_WITH_COPY_TO_OUTSIDE = _SAMPLE_WITH_DIR + b"""\
+commit refs/heads/master
mark :103
committer d <b@c> 1234798653 +0000
data 10
@@ -618,8 +623,8 @@ C doc/README.txt README
# doc/index.txt
#
# It then copies NEWS => doc/NEWS
-_SAMPLE_WITH_COPY_TO_INSIDE = _SAMPLE_WITH_DIR + \
-b"""commit refs/heads/master
+_SAMPLE_WITH_COPY_TO_INSIDE = _SAMPLE_WITH_DIR + b"""\
+commit refs/heads/master
mark :103
committer d <b@c> 1234798653 +0000
data 10
@@ -634,8 +639,8 @@ class TestIncludePathsWithCopies(TestCaseWithFiltering):
def test_copy_all_inside(self):
# These copy commands ought to be kept but adjusted for the new root
params = {b'include_paths': [b'doc/']}
- self.assertFiltering(_SAMPLE_WITH_COPY_INSIDE, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_WITH_COPY_INSIDE, params, b"""\
+blob
mark :1
data 9
Welcome!
@@ -675,8 +680,8 @@ C README.txt README
def test_copy_to_outside(self):
# This can be ignored
params = {b'include_paths': [b'doc/']}
- self.assertFiltering(_SAMPLE_WITH_COPY_TO_OUTSIDE, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_WITH_COPY_TO_OUTSIDE, params, b"""\
+blob
mark :1
data 9
Welcome!
@@ -709,8 +714,8 @@ M 644 :4 index.txt
def test_copy_to_inside(self):
# This ought to create a new file but doesn't yet
params = {b'include_paths': [b'doc/']}
- self.assertFiltering(_SAMPLE_WITH_COPY_TO_INSIDE, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_WITH_COPY_TO_INSIDE, params, b"""\
+blob
mark :1
data 9
Welcome!
@@ -746,8 +751,8 @@ M 644 :4 index.txt
# NEWS
# doc/README.txt
# doc/index.txt
-_SAMPLE_WITH_DELETEALL = \
-b"""blob
+_SAMPLE_WITH_DELETEALL = b"""\
+blob
mark :1
data 9
Welcome!
@@ -784,8 +789,8 @@ class TestIncludePathsWithDeleteAll(TestCaseWithFiltering):
def test_deleteall(self):
params = {b'include_paths': [b'doc/index.txt']}
- self.assertFiltering(_SAMPLE_WITH_DELETEALL, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_WITH_DELETEALL, params, b"""\
+blob
mark :4
data 11
== Docs ==
@@ -801,8 +806,8 @@ M 644 :4 index.txt
""")
-_SAMPLE_WITH_TAGS = _SAMPLE_WITH_DIR + \
-b"""tag v0.1
+_SAMPLE_WITH_TAGS = _SAMPLE_WITH_DIR + b"""\
+tag v0.1
from :100
tagger d <b@c> 1234798653 +0000
data 12
@@ -814,6 +819,7 @@ data 12
release v0.2
"""
+
class TestIncludePathsWithTags(TestCaseWithFiltering):
def test_tag_retention(self):
@@ -821,8 +827,8 @@ class TestIncludePathsWithTags(TestCaseWithFiltering):
# keep the tag but adjust 'from' accordingly.
# Otherwise, delete the tag command.
params = {b'include_paths': [b'NEWS']}
- self.assertFiltering(_SAMPLE_WITH_TAGS, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_WITH_TAGS, params, b"""\
+blob
mark :2
data 17
Life
@@ -843,12 +849,13 @@ release v0.2
""")
-_SAMPLE_WITH_RESETS = _SAMPLE_WITH_DIR + \
-b"""reset refs/heads/foo
+_SAMPLE_WITH_RESETS = _SAMPLE_WITH_DIR + b"""\
+reset refs/heads/foo
reset refs/heads/bar
from :102
"""
+
class TestIncludePathsWithResets(TestCaseWithFiltering):
def test_reset_retention(self):
@@ -856,8 +863,8 @@ class TestIncludePathsWithResets(TestCaseWithFiltering):
# If a reset references a commit with a parent we kept,
# keep the reset but adjust 'from' accordingly.
params = {b'include_paths': [b'NEWS']}
- self.assertFiltering(_SAMPLE_WITH_RESETS, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_WITH_RESETS, params, b"""\
+blob
mark :2
data 17
Life
@@ -877,8 +884,8 @@ from :101
# A sample input stream containing empty commit
-_SAMPLE_EMPTY_COMMIT = \
-b"""blob
+_SAMPLE_EMPTY_COMMIT = b"""\
+blob
mark :1
data 4
foo
@@ -896,8 +903,8 @@ empty commit
"""
# A sample input stream containing unresolved from and merge references
-_SAMPLE_FROM_MERGE_COMMIT = \
-b"""blob
+_SAMPLE_FROM_MERGE_COMMIT = b"""\
+blob
mark :1
data 4
foo
@@ -933,12 +940,13 @@ merge :1001
M 644 :99 data/DATA2
"""
+
class TestSquashEmptyCommitsFlag(TestCaseWithFiltering):
def test_squash_empty_commit(self):
params = {b'include_paths': None, b'exclude_paths': None}
- self.assertFiltering(_SAMPLE_EMPTY_COMMIT, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_EMPTY_COMMIT, params, b"""\
+blob
mark :1
data 4
foo
@@ -951,13 +959,18 @@ M 644 :1 COPYING
""")
def test_keep_empty_commit(self):
- params = {b'include_paths': None, b'exclude_paths': None, b'squash_empty_commits': False}
- self.assertFiltering(_SAMPLE_EMPTY_COMMIT, params, _SAMPLE_EMPTY_COMMIT)
+ params = {
+ b'include_paths': None,
+ b'exclude_paths': None,
+ b'squash_empty_commits': False,
+ }
+ self.assertFiltering(
+ _SAMPLE_EMPTY_COMMIT, params, _SAMPLE_EMPTY_COMMIT)
def test_squash_unresolved_references(self):
params = {b'include_paths': None, b'exclude_paths': None}
- self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, b"""\
+blob
mark :1
data 4
foo
@@ -994,15 +1007,20 @@ M 644 :99 data/DATA2
""")
def test_keep_unresolved_from_and_merge(self):
- params = {b'include_paths': None, b'exclude_paths': None, b'squash_empty_commits': False}
- self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, _SAMPLE_FROM_MERGE_COMMIT)
+ params = {
+ b'include_paths': None,
+ b'exclude_paths': None,
+ b'squash_empty_commits': False,
+ }
+ self.assertFiltering(
+ _SAMPLE_FROM_MERGE_COMMIT, params, _SAMPLE_FROM_MERGE_COMMIT)
def test_with_excludes(self):
params = {b'include_paths': None,
b'exclude_paths': [b'data/DATA'],
b'squash_empty_commits': False}
- self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, b"""\
+blob
mark :1
data 4
foo
@@ -1037,8 +1055,8 @@ M 644 :99 data/DATA2
params = {b'include_paths': [b'COPYING', b'data/DATA2'],
b'exclude_paths': None,
b'squash_empty_commits': False}
- self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, \
-b"""blob
+ self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, b"""\
+blob
mark :1
data 4
foo
@@ -1067,15 +1085,14 @@ from :3
merge :4
merge :1001
M 644 :99 data/DATA2
-"""
-)
+""")
def test_with_directory_includes(self):
params = {b'include_paths': [b'data/'],
b'exclude_paths': None,
b'squash_empty_commits': False}
- self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, \
-b"""commit refs/heads/master
+ self.assertFiltering(_SAMPLE_FROM_MERGE_COMMIT, params, b"""\
+commit refs/heads/master
mark :3
committer Joe <joe@example.com> 1234567890 +1000
data 6
diff --git a/fastimport/tests/test_helpers.py b/fastimport/tests/test_helpers.py
index 3198cea..f695a60 100644
--- a/fastimport/tests/test_helpers.py
+++ b/fastimport/tests/test_helpers.py
@@ -51,5 +51,6 @@ class TestCommonDirectory(unittest.TestCase):
self.assertEqual(c, b'foo/bar/')
def test_lots_of_paths(self):
- c = helpers.common_directory([b'foo/bar/x', b'foo/bar/y', b'foo/bar/z'])
+ c = helpers.common_directory(
+ [b'foo/bar/x', b'foo/bar/y', b'foo/bar/z'])
self.assertEqual(c, b'foo/bar/')
diff --git a/fastimport/tests/test_info_processor.py b/fastimport/tests/test_info_processor.py
index 6904b50..f86fd1f 100644
--- a/fastimport/tests/test_info_processor.py
+++ b/fastimport/tests/test_info_processor.py
@@ -39,6 +39,7 @@ initial
"""
+
class TestFastImportInfo(TestCase):
def test_simple(self):
diff --git a/fastimport/tests/test_parser.py b/fastimport/tests/test_parser.py
index 5084dc9..cfbe096 100644
--- a/fastimport/tests/test_parser.py
+++ b/fastimport/tests/test_parser.py
@@ -143,10 +143,14 @@ 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
@@ -181,9 +185,12 @@ class TestImportParser(unittest.TestCase):
self.assertEqual(b'commit', cmd4.name)
self.assertEqual(b'2', cmd4.mark)
self.assertEqual(b':2', cmd4.id)
- self.assertEqual(b'initial import', cmd4.message)
+ self.assertEqual(
+ b'initial import', cmd4.message)
- self.assertEqual((b'bugs bunny', b'bugs@bunny.org', self.fake_time, 0), cmd4.committer)
+ self.assertEqual(
+ (b'bugs bunny', b'bugs@bunny.org', self.fake_time, 0),
+ cmd4.committer)
# namedtuple attributes
self.assertEqual(b'bugs bunny', cmd4.committer.name)
self.assertEqual(b'bugs@bunny.org', cmd4.committer.email)
@@ -205,7 +212,8 @@ class TestImportParser(unittest.TestCase):
self.assertEqual(None, cmd5.mark)
self.assertEqual(b'@19', cmd5.id)
self.assertEqual(b'second commit', cmd5.message)
- self.assertEqual((b'', b'bugs@bunny.org', self.fake_time, 0), cmd5.committer)
+ self.assertEqual(
+ (b'', b'bugs@bunny.org', self.fake_time, 0), cmd5.committer)
self.assertEqual(None, cmd5.author)
self.assertEqual(19, cmd5.lineno)
self.assertEqual(b'refs/heads/master', cmd5.ref)
@@ -300,7 +308,8 @@ class TestStringParsing(unittest.TestCase):
def test_unquote(self):
s = br'hello \"sweet\" wo\\r\tld'
- self.assertEqual(br'hello "sweet" wo\r' + b'\tld',
+ self.assertEqual(
+ br'hello "sweet" wo\r' + b'\tld',
parser._unquote_c_string(s))
@@ -312,7 +321,8 @@ class TestPathPairParsing(unittest.TestCase):
def test_path_pair_spaces_in_first(self):
p = parser.ImportParser("")
- self.assertEqual([b'foo bar', b'baz'],
+ self.assertEqual(
+ [b'foo bar', b'baz'],
p._path_pair(b'"foo bar" baz'))
@@ -328,7 +338,8 @@ class TestTagParsing(unittest.TestCase):
cmds = list(p.iter_commands())
self.assertEqual(1, len(cmds))
self.assertTrue(isinstance(cmds[0], commands.TagCommand))
- self.assertEqual(cmds[0].tagger,
+ self.assertEqual(
+ cmds[0].tagger,
(b'Joe Wong', b'joe@example.com', 1234567890.0, -21600))
def test_tagger_no_email_strict(self):
diff --git a/setup.py b/setup.py
index d4a5316..5f3914a 100755
--- a/setup.py
+++ b/setup.py
@@ -20,7 +20,8 @@ setup(name="fastimport",
],
classifiers=[
'Development Status :: 4 - Beta',
- 'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)',
+ 'License :: OSI Approved :: GNU General Public License v2 '
+ 'or later (GPLv2+)',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',