Stop adding extra newline after unparseable lines.

I have a project that includes a requirement line this:

    -e git://git.openstack.org/openstack/neutron.git#egg=neutron

Every time update.py runs against the file, it adds an extra newline
after this.  For example, if I run update.py a few times, I'll have a
few new lines in the file.  This patch prevents the extra newlines
from getting added.

Change-Id: I92d02a45c437025b16df067d7b58a3727d42c0e0
Signed-off-by: Russell Bryant <rbryant@redhat.com>
This commit is contained in:
Russell Bryant 2015-07-07 11:02:48 -04:00
parent a6aa3da227
commit 931defba21
2 changed files with 19 additions and 1 deletions

View File

@ -111,7 +111,7 @@ def _sync_requirements_file(
elif req is None:
# Unparsable lines.
output_requirements.append(
requirement.Requirement('', '', '', '', req_line))
requirement.Requirement('', '', '', '', req_line.rstrip()))
continue
elif not req.package:
# Comment-only lines

View File

@ -366,6 +366,24 @@ class TestSyncRequirementsFile(testtools.TestCase):
" foo>1;python_version!='2.7' -> \n"), actions[3])
self.assertThat(actions, matchers.HasLength(4))
def test_unparseable_line(self):
global_content = textwrap.dedent("""\
foo
""")
project_content = textwrap.dedent("""\
foo
-e git://git.openstack.org/openstack/neutron.git#egg=neutron
""")
global_reqs = requirement.parse(global_content)
project_reqs = list(requirement.to_reqs(project_content))
actions, reqs = update._sync_requirements_file(
global_reqs, project_reqs, 'f', False, False, False)
n = '-e git://git.openstack.org/openstack/neutron.git#egg=neutron'
self.assertEqual(requirement.Requirements([
requirement.Requirement('foo', '', '', '', ''),
requirement.Requirement('', '', '', '', n)]),
reqs)
class TestCopyRequires(testtools.TestCase):