@@ -946,23 +946,8 @@ def test_generate_hashes_with_annotations(runner):
946946 ("--annotation-style" , "split" ),
947947 ),
948948)
949- @pytest .mark .parametrize (
950- ("nl_options" , "must_include" , "must_exclude" ),
951- (
952- pytest .param (("--newline" , "lf" ), "\n " , "\r \n " , id = "LF" ),
953- pytest .param (("--newline" , "crlf" ), "\r \n " , "\n " , id = "CRLF" ),
954- pytest .param (
955- ("--newline" , "native" ),
956- os .linesep ,
957- {"\n " : "\r \n " , "\r \n " : "\n " }[os .linesep ],
958- id = "native" ,
959- ),
960- ),
961- )
962- def test_override_newline (
963- runner , gen_hashes , annotate_options , nl_options , must_include , must_exclude
964- ):
965- opts = annotate_options + nl_options
949+ def test_force_lf_newlines (runner , gen_hashes , annotate_options ):
950+ opts = (* annotate_options , "--force-lf-newlines" )
966951 if gen_hashes :
967952 opts += ("--generate-hashes" ,)
968953
@@ -975,39 +960,36 @@ def test_override_newline(
975960 with open ("requirements.txt" , "rb" ) as req_txt :
976961 txt = req_txt .read ().decode ()
977962
978- assert must_include in txt
963+ assert "\n " in txt
964+ assert "\r \n " not in txt
979965
980- if must_exclude in must_include :
981- txt = txt .replace (must_include , "" )
982- assert must_exclude not in txt
983-
984- # Do it again, with --newline=preserve:
985966
986- opts = annotate_options + ("--newline" , "preserve" )
987- if gen_hashes :
988- opts += ("--generate-hashes" ,)
967+ @pytest .mark .network
968+ @pytest .mark .parametrize (
969+ ("linesep" , "must_exclude" ),
970+ (pytest .param ("\n " , "\r \n " , id = "LF" ), pytest .param ("\r \n " , "\n " , id = "CRLF" )),
971+ )
972+ def test_preserve_newlines_from_output_or_input (runner , linesep , must_exclude ):
973+ with open ("requirements.in" , "wb" ) as req_in :
974+ req_in .write (f"six{ linesep } " .encode ())
989975
990- runner .invoke (cli , [* opts , "requirements.in" ])
976+ runner .invoke (cli , ["requirements.in" ])
991977 with open ("requirements.txt" , "rb" ) as req_txt :
992978 txt = req_txt .read ().decode ()
993979
994- assert must_include in txt
980+ assert linesep in txt
995981
996- if must_exclude in must_include :
997- txt = txt .replace (must_include , "" )
982+ if must_exclude in linesep :
983+ txt = txt .replace (linesep , "" )
998984 assert must_exclude not in txt
999985
986+ # Now that we have good output,
987+ # see that it's preserved when we have bad input:
1000988
1001- @pytest .mark .network
1002- @pytest .mark .parametrize (
1003- ("linesep" , "must_exclude" ),
1004- (pytest .param ("\n " , "\r \n " , id = "LF" ), pytest .param ("\r \n " , "\n " , id = "CRLF" )),
1005- )
1006- def test_preserve_newline_from_input (runner , linesep , must_exclude ):
1007989 with open ("requirements.in" , "wb" ) as req_in :
1008- req_in .write (f"six{ linesep } " .encode ())
990+ req_in .write (f"six{ must_exclude } " .encode ())
1009991
1010- runner .invoke (cli , ["--newline=preserve" , " requirements.in" ])
992+ runner .invoke (cli , ["requirements.in" ])
1011993 with open ("requirements.txt" , "rb" ) as req_txt :
1012994 txt = req_txt .read ().decode ()
1013995
0 commit comments