Skip to content

Commit

Permalink
Change write_lock to emit a more minimal if --no-header is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
lfdebrux committed Apr 3, 2020
1 parent b77b3d7 commit 487e4b6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
7 changes: 5 additions & 2 deletions piptools/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ def write_find_links(self):

def write_lock(self):
if self.emit_lock:
yield comment("# This file was locked against the following input files:")
yield comment("#")
if self.emit_header:
yield comment(
"# This file was locked against the following input files:"
)
yield comment("#")

for lock in generate_locks(*self.src_files).values():
yield comment("# {}".format(lock))
Expand Down
19 changes: 19 additions & 0 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,25 @@ def test_write_lock(writer):
assert list(writer.write_lock()) == list(expected)


def test_write_lock_no_header(writer):
"""
Test write_lock method with --no-header option.
"""
writer.emit_lock = True
writer.emit_header = False
expected = map(
comment,
[
"# sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
" src_file",
"# sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
" src_file2",
"#",
],
)
assert list(writer.write_lock()) == list(expected)


def test_write_lock_no_emit_lock(writer):
"""
There should be no locks if emit_lock is False
Expand Down

0 comments on commit 487e4b6

Please sign in to comment.