Skip to content

Commit

Permalink
testsuite: archiver: use os.linesep instead of hardcoded newline string
Browse files Browse the repository at this point in the history
On Windows, a newline is \r\n instead of \n.
  • Loading branch information
RayyanAnsari committed Nov 29, 2022
1 parent c18121b commit 0d3eeca
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/borg/testsuite/archiver/config_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ def test_config(self):
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)

Expand Down
8 changes: 4 additions & 4 deletions src/borg/testsuite/archiver/create_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,14 +204,14 @@ def test_create_content_from_command_with_failed_command(self):
"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)
Expand Down Expand Up @@ -262,14 +262,14 @@ def test_create_paths_from_command_with_failed_command(self):
"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"""
Expand Down
2 changes: 1 addition & 1 deletion src/borg/testsuite/archiver/debug_cmds.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_debug_refcount_obj(self):

# 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")
Expand Down
5 changes: 3 additions & 2 deletions src/borg/testsuite/archiver/info_cmd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
import unittest

from ...constants import * # NOQA
Expand All @@ -18,9 +19,9 @@ def test_info(self):
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)
Expand Down
4 changes: 2 additions & 2 deletions src/borg/testsuite/archiver/recreate_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def test_comment(self):
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")
Expand All @@ -274,7 +274,7 @@ def test_comment(self):
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")


Expand Down
7 changes: 4 additions & 3 deletions src/borg/testsuite/archiver/rlist_cmd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
import os
import unittest

from ...constants import * # NOQA
Expand Down Expand Up @@ -34,12 +35,12 @@ def test_archives_format(self):
)
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_1 = self.cmd(f"--repo={self.repository_location}", "rlist", "--format", "{barchive}/")
self.assertEqual(output_1, "test-1/test-2/")
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)
Expand Down

0 comments on commit 0d3eeca

Please sign in to comment.