From 931defba21326ead465fff5000f4e511884eb926 Mon Sep 17 00:00:00 2001
From: Russell Bryant <rbryant@redhat.com>
Date: Tue, 7 Jul 2015 11:02:48 -0400
Subject: [PATCH] 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>
---
 openstack_requirements/cmds/update.py       |  2 +-
 openstack_requirements/tests/test_update.py | 18 ++++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/openstack_requirements/cmds/update.py b/openstack_requirements/cmds/update.py
index 10bba91c87..503e78edad 100644
--- a/openstack_requirements/cmds/update.py
+++ b/openstack_requirements/cmds/update.py
@@ -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
diff --git a/openstack_requirements/tests/test_update.py b/openstack_requirements/tests/test_update.py
index 1d02b1e718..67b965d863 100644
--- a/openstack_requirements/tests/test_update.py
+++ b/openstack_requirements/tests/test_update.py
@@ -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):