Last active
November 9, 2021 16:24
-
-
Save abadger/19b31a1cd186c1dddd7351cba77b90a3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| diff --git a/convert2rhel/unit_tests/logger_test.py b/convert2rhel/unit_tests/logger_test.py | |
| index 1679f66..78477cc 100644 | |
| --- a/convert2rhel/unit_tests/logger_test.py | |
| +++ b/convert2rhel/unit_tests/logger_test.py | |
| @@ -119,20 +119,29 @@ def test_logger_custom_logger(tmpdir, caplog): | |
| ("convert2rhel.log", True, False, True), | |
| ), | |
| ) | |
| [email protected]("os.stat") | |
| -def test_archive_old_logger_files(os_stat, log_name, path_exists, is_dir, exception, monkeypatch, caplog): | |
| - path_exists_mock = mock.MagicMock(return_value=path_exists) | |
| - is_dir_mock = mock.MagicMock(return_value=is_dir) | |
| - shutil_mock = mock.MagicMock(return_value=None) | |
| +def test_archive_old_logger_files(log_name, path_exists, is_dir, exception, tmpdir, caplog): | |
| - monkeypatch.setattr(os.path, "exists", value=path_exists_mock) | |
| - monkeypatch.setattr(os.path, "isdir", value=is_dir_mock) | |
| - monkeypatch.setattr(shutil, "copyfile", value=shutil_mock) | |
| + archive_dir = os.path.join(tmpdir, "archive") | |
| + log_file = os.path.join(tmpdir, log_name) | |
| + test_data = "test data\n" | |
| - os_stat.return_value.st_mtime_ns = 1234 | |
| + # Test that we error when the archive_dir is a file. | |
| + if not is_dir: | |
| + open(archive_dir, "w").write("\n") | |
| + | |
| + # Test that the current log file can either exist or not exist | |
| + if path_exists: | |
| + open(log_file, "w").write(test_data) | |
| if exception: | |
| with pytest.raises(IOError): | |
| - logger_module.archive_old_logger_files(log_name) | |
| + logger_module.archive_old_logger_files(log_name, log_dir=tmpdir) | |
| else: | |
| - assert logger_module.archive_old_logger_files(log_name) is None | |
| + logger_module.archive_old_logger_files(log_name, log_dir=tmpdir) | |
| + if path_exists: | |
| + assert "archive" in os.listdir(tmpdir) | |
| + | |
| + archive_files = os.listdir(archive_dir) | |
| + assert len(archive_files) == 1 | |
| + with open(os.path.join(archive_dir, archive_files[0])) as archive_f: | |
| + assert archive_f.read() == test_data |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment