@@ -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\t example.com\t example\n " )
570+ import_file = tmpdir .mkdir ("input" ).join ("infile" )
571+ import_file .write ("10.10.10.10\t hello.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\t example.com\t example\n " )
585+ import_file = tmpdir .mkdir ("input" ).join ("infile" )
586+ import_file .write ("10.10.10.10\t hello.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+
564595def 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