Skip to content

Commit

Permalink
merge get log content and fix windows tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jedie committed Jan 21, 2016
1 parent 8864afd commit 67bcee4
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
6 changes: 6 additions & 0 deletions PyHardLinkBackup/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,12 @@ def setUp(self):
def get_newest_backup_path(self):
return get_newest_directory(self.backup_sub_path)

def get_log_content(self, log_filepath):
self.assertTrue(log_filepath.is_file(), "%s doesn't exist" % log_filepath)

with log_filepath.open("r") as f: # Path().read_text() is new in Py 2.5
return f.read()


class BaseWithSourceFilesTestCase(BaseSourceDirTestCase):
"""
Expand Down
12 changes: 5 additions & 7 deletions PyHardLinkBackup/tests/test_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

import pathlib

import sys

from PyHardLinkBackup.tests.base import BaseCreatedTwoBackupsTestCase, BaseCreatedOneBackupsTestCase
from PyHardLinkBackup.tests.utils import UnittestFileSystemHelper

Expand Down Expand Up @@ -67,15 +69,13 @@ def test_summary(self):


def test_log_file(self):
self.assertTrue(self.first_run_log.is_file(), "%s doesn't exist" % self.first_run_log)

with self.first_run_log.open("r") as f: # Path().read_text() is new in Py 2.5
log_content = f.read()
log_content = self.get_log_content(self.first_run_log)

print(log_content)
self.assertIn("Backup", log_content)
self.assertIn("Start low level logging", log_content)

@unittest.skipIf(sys.platform.startswith("win"), "TODO: work-a-round for os.chmod()")
def test_skip_files(self):
"""
Test if not open able source files, will be skipped
Expand All @@ -98,9 +98,7 @@ def test_skip_files(self):
self.assertEqual(os.listdir(self.backup_path), ["source unittests files"])
self.assert_backup_fs_count(2)

with self.first_run_log.open("r") as f: # Path().read_text() is new in Py 2.5
log_content = f.read()

log_content = self.get_log_content(self.first_run_log)
print(log_content)
self.assertIn("Skip file", log_content)
self.assertIn("/root_file_B.txt error:", log_content)
Expand Down
14 changes: 6 additions & 8 deletions PyHardLinkBackup/tests/test_windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,8 @@ def test_link_limit(self):
compare_list.append('file %04i.txt.sha512 F - e3770...f651c' % no)

print("Backup all files")
with self.assertLogs(logging.getLogger("phlb"), level=logging.INFO) as cm:
result = self.invoke_cli("backup", self.source_path)
# print(result.output)
logs = cm.output[:3] + ["..."] + cm.output[-3:]

logs = "\n".join(cm.output)
self.assertIn("Replaced with a hardlink", logs)
self.assertNotIn("ERROR", logs)
result = self.invoke_cli("backup", self.source_path)
# print(result.output)

self.assertIn("9.0 KB in 1022 files to backup.", result.output)
self.assertIn("new content to saved: 1 files (9 Bytes 0.1%)", result.output)
Expand All @@ -81,6 +75,10 @@ def test_link_limit(self):

first_run_path = self.get_newest_backup_path()

log_content = self.get_log_content(pathlib.Path(first_run_path + ".log"))
self.assertIn("Replaced with a hardlink", log_content)
self.assertNotIn("ERROR", log_content)

compare_list.insert(0, first_run_path)
# print("\n".join(compare_list))

Expand Down

0 comments on commit 67bcee4

Please sign in to comment.