Explorar el Código

testsuite: archiver: use os.linesep instead of hardcoded newline string

On Windows, a newline is \r\n instead of \n.
Rayyan Ansari hace 2 años
padre
commit
2f9c7d98e5

+ 3 - 3
src/borg/testsuite/archiver/config_cmd.py

@@ -24,17 +24,17 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         self.assert_in("No option ", output)
         self.cmd(f"--repo={self.repository_location}", "config", "last_segment_checked", "123")
         output = self.cmd(f"--repo={self.repository_location}", "config", "last_segment_checked")
-        assert output == "123" + "\n"
+        assert output == "123" + os.linesep
         output = self.cmd(f"--repo={self.repository_location}", "config", "--list")
         self.assert_in("last_segment_checked", output)
         self.cmd(f"--repo={self.repository_location}", "config", "--delete", "last_segment_checked")
 
         for cfg_key, cfg_value in [("additional_free_space", "2G"), ("repository.append_only", "1")]:
             output = self.cmd(f"--repo={self.repository_location}", "config", cfg_key)
-            assert output == "0" + "\n"
+            assert output == "0" + os.linesep
             self.cmd(f"--repo={self.repository_location}", "config", cfg_key, cfg_value)
             output = self.cmd(f"--repo={self.repository_location}", "config", cfg_key)
-            assert output == cfg_value + "\n"
+            assert output == cfg_value + os.linesep
             self.cmd(f"--repo={self.repository_location}", "config", "--delete", cfg_key)
             self.cmd(f"--repo={self.repository_location}", "config", cfg_key, exit_code=1)
 

+ 4 - 4
src/borg/testsuite/archiver/create_cmd.py

@@ -204,14 +204,14 @@ class ArchiverTestCase(ArchiverTestCaseBase):
             "exit 73;",
             exit_code=2,
         )
-        assert output.endswith("Command 'sh' exited with status 73\n")
+        assert output.endswith("Command 'sh' exited with status 73" + os.linesep)
         archive_list = json.loads(self.cmd(f"--repo={self.repository_location}", "rlist", "--json"))
         assert archive_list["archives"] == []
 
     def test_create_content_from_command_missing_command(self):
         self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
         output = self.cmd(f"--repo={self.repository_location}", "create", "test", "--content-from-command", exit_code=2)
-        assert output.endswith("No command given.\n")
+        assert output.endswith("No command given." + os.linesep)
 
     def test_create_paths_from_stdin(self):
         self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
@@ -262,14 +262,14 @@ class ArchiverTestCase(ArchiverTestCaseBase):
             "exit 73;",
             exit_code=2,
         )
-        assert output.endswith("Command 'sh' exited with status 73\n")
+        assert output.endswith("Command 'sh' exited with status 73" + os.linesep)
         archive_list = json.loads(self.cmd(f"--repo={self.repository_location}", "rlist", "--json"))
         assert archive_list["archives"] == []
 
     def test_create_paths_from_command_missing_command(self):
         self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
         output = self.cmd(f"--repo={self.repository_location}", "create", "test", "--paths-from-command", exit_code=2)
-        assert output.endswith("No command given.\n")
+        assert output.endswith("No command given." + os.linesep)
 
     def test_create_without_root(self):
         """test create without a root"""

+ 1 - 1
src/borg/testsuite/archiver/debug_cmds.py

@@ -107,7 +107,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
 
         # Invalid IDs do not abort or return an error
         output = self.cmd(f"--repo={self.repository_location}", "debug", "refcount-obj", "124", "xyza").strip()
-        assert output == "object id 124 is invalid.\nobject id xyza is invalid."
+        assert output == "object id 124 is invalid." + os.linesep + "object id xyza is invalid."
 
     def test_debug_info(self):
         output = self.cmd("debug", "info")

+ 3 - 2
src/borg/testsuite/archiver/info_cmd.py

@@ -1,4 +1,5 @@
 import json
+import os
 import unittest
 
 from ...constants import *  # NOQA
@@ -18,9 +19,9 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)
         self.cmd(f"--repo={self.repository_location}", "create", "test", "input")
         info_archive = self.cmd(f"--repo={self.repository_location}", "info", "-a", "test")
-        assert "Archive name: test\n" in info_archive
+        assert "Archive name: test" + os.linesep in info_archive
         info_archive = self.cmd(f"--repo={self.repository_location}", "info", "--first", "1")
-        assert "Archive name: test\n" in info_archive
+        assert "Archive name: test" + os.linesep in info_archive
 
     def test_info_json(self):
         self.create_regular_file("file1", size=1024 * 80)

+ 2 - 2
src/borg/testsuite/archiver/recreate_cmd.py

@@ -265,7 +265,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         self.cmd(f"--repo={self.repository_location}", "create", "test2", "input", "--comment", "this is the comment")
         self.cmd(f"--repo={self.repository_location}", "create", "test3", "input", "--comment", '"deleted" comment')
         self.cmd(f"--repo={self.repository_location}", "create", "test4", "input", "--comment", "preserved comment")
-        assert "Comment: \n" in self.cmd(f"--repo={self.repository_location}", "info", "-a", "test1")
+        assert "Comment: " + os.linesep in self.cmd(f"--repo={self.repository_location}", "info", "-a", "test1")
         assert "Comment: this is the comment" in self.cmd(f"--repo={self.repository_location}", "info", "-a", "test2")
 
         self.cmd(f"--repo={self.repository_location}", "recreate", "-a", "test1", "--comment", "added comment")
@@ -274,7 +274,7 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         self.cmd(f"--repo={self.repository_location}", "recreate", "-a", "test4", "12345")
         assert "Comment: added comment" in self.cmd(f"--repo={self.repository_location}", "info", "-a", "test1")
         assert "Comment: modified comment" in self.cmd(f"--repo={self.repository_location}", "info", "-a", "test2")
-        assert "Comment: \n" in self.cmd(f"--repo={self.repository_location}", "info", "-a", "test3")
+        assert "Comment: " + os.linesep in self.cmd(f"--repo={self.repository_location}", "info", "-a", "test3")
         assert "Comment: preserved comment" in self.cmd(f"--repo={self.repository_location}", "info", "-a", "test4")
 
 

+ 4 - 3
src/borg/testsuite/archiver/rlist_cmd.py

@@ -1,4 +1,5 @@
 import json
+import os
 import unittest
 
 from ...constants import *  # NOQA
@@ -34,10 +35,10 @@ class ArchiverTestCase(ArchiverTestCaseBase):
         )
         self.assertEqual(output_1, output_2)
         output_1 = self.cmd(f"--repo={self.repository_location}", "rlist", "--short")
-        self.assertEqual(output_1, "test-1\ntest-2\n")
+        self.assertEqual(output_1, "test-1" + os.linesep + "test-2" + os.linesep)
         output_3 = self.cmd(f"--repo={self.repository_location}", "rlist", "--format", "{name} {comment}{NL}")
-        self.assert_in("test-1 comment 1\n", output_3)
-        self.assert_in("test-2 comment 2\n", output_3)
+        self.assert_in("test-1 comment 1" + os.linesep, output_3)
+        self.assert_in("test-2 comment 2" + os.linesep, output_3)
 
     def test_rlist_consider_checkpoints(self):
         self.cmd(f"--repo={self.repository_location}", "rcreate", RK_ENCRYPTION)