Skip to content

Commit 72f5046

Browse files
committed
add tests for importing files with comments, and inline comments.
1 parent d3820c6 commit 72f5046

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/test_hosts.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,37 @@ def test_import_file_returns_duplicate_correctly(tmpdir):
561561
assert write_result.get('ipv4_entries_written') == 2
562562

563563

564+
def test_import_file_persists_inline_comments(tmpdir):
565+
"""
566+
Test that importing an entry from a file will persist inline comments
567+
"""
568+
hosts_file = tmpdir.mkdir("etc").join("hosts")
569+
hosts_file.write("82.132.132.132\texample.com\texample\n")
570+
import_file = tmpdir.mkdir("input").join("infile")
571+
import_file.write("10.10.10.10\thello.com # testing\n")
572+
hosts_entries = Hosts(path=hosts_file.strpath)
573+
feedback = hosts_entries.import_file(import_file_path=import_file.strpath)
574+
write_result = feedback.get('write_result')
575+
assert write_result.get('ipv4_entries_written') == 2
576+
assert hosts_entries.entries[1].comment == 'testing'
577+
578+
579+
def test_import_file_persists_comments(tmpdir):
580+
"""
581+
Test that importing an entry from a file will persist comments
582+
"""
583+
hosts_file = tmpdir.mkdir("etc").join("hosts")
584+
hosts_file.write("# 82.132.132.132\texample.com\texample\n")
585+
import_file = tmpdir.mkdir("input").join("infile")
586+
import_file.write("10.10.10.10\thello.com # testing\n")
587+
hosts_entries = Hosts(path=hosts_file.strpath)
588+
feedback = hosts_entries.import_file(import_file_path=import_file.strpath)
589+
write_result = feedback.get('write_result')
590+
assert write_result.get('ipv4_entries_written') == 1
591+
assert write_result.get('comments_written') == 1
592+
assert hosts_entries.entries[1].comment == 'testing'
593+
594+
564595
def test_addition_of_ipv6_entry_where_matching_name_exists_and_force_false(tmpdir):
565596
"""
566597
Test no replacement of an ipv6 entry where the address is different

0 commit comments

Comments
 (0)