Skip to content

Commit

Permalink
Fix missing newlines when using --dry-run-changed option
Browse files Browse the repository at this point in the history
  • Loading branch information
alanhamlett committed Sep 4, 2023
1 parent 05af5f6 commit 48f2788
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
7 changes: 4 additions & 3 deletions pur/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ def _update_requirements(obuffer, updates, input_file=None,
spec_ver,
latest_ver)
obuffer.write(new_line)
obuffer.write('\n')

if new_line != line:
msg = 'Updated {package}: {old} -> {new}'.format(
Expand Down Expand Up @@ -308,17 +309,17 @@ def _update_requirements(obuffer, updates, input_file=None,

elif not dry_run_changed:
obuffer.write(line)
obuffer.write('\n')

except StopUpdating:
stop = True
if not dry_run_changed:
obuffer.write(line)
obuffer.write('\n')

elif not output_buffer or not requirements_line(line, req):
if not dry_run_changed:
obuffer.write(line)

if not output_buffer or not requirements_line(line, req):
if not dry_run_changed:
obuffer.write('\n')

if dry_run and echo:
Expand Down
3 changes: 3 additions & 0 deletions tests/samples/results/test_dry_run_changed
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
flask==0.10.1
Alembic==0.10.1
sqlalchemy==0.10.1

5 changes: 2 additions & 3 deletions tests/test_pur.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,7 +923,7 @@ def test_dry_run_invalid_package(self):
self.assertEqual(open(tmpfile).read(), open(requirements).read())

def test_dry_run_changed(self):
requirements = 'tests/samples/requirements.txt'
requirements = 'tests/samples/requirements-multiple.txt'
tempdir = tempfile.mkdtemp()
tmpfile = os.path.join(tempdir, 'requirements.txt')
shutil.copy(requirements, tmpfile)
Expand All @@ -938,8 +938,7 @@ def test_dry_run_changed(self):

result = self.runner.invoke(pur, args)
self.assertIsNone(result.exception)
expected_output = '==> ' + tmpfile + ' <==\n' + \
open('tests/samples/results/test_dry_run_changed').read()
expected_output = '==> ' + tmpfile + ' <==\n' + open('tests/samples/results/test_dry_run_changed').read()
self.assertEqual(u(result.output), u(expected_output))
self.assertEqual(result.exit_code, 0)
self.assertEqual(open(tmpfile).read(), open(requirements).read())
Expand Down

0 comments on commit 48f2788

Please sign in to comment.