From 9d0a42515bf35daef19818ce7e8bad7b1d64804f Mon Sep 17 00:00:00 2001 From: chrpetre Date: Mon, 12 Feb 2024 13:19:42 +0100 Subject: [PATCH 1/8] Update test_settings.py --- tests/test_settings.py | 45 +++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/tests/test_settings.py b/tests/test_settings.py index 14c7a43d..76edd146 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -14,7 +14,7 @@ pytwin_logging_is_enabled, ) -# import tempfile +import tempfile UNIT_TEST_WD = os.path.join(os.path.dirname(__file__), "unit_test_wd") @@ -30,27 +30,28 @@ def reinit_settings(): class TestDefaultSettings: - # def test_default_setting(self): - # # Working directory is created in temp folder - # wd = get_pytwin_working_dir() - # assert tempfile.gettempdir() in wd - # assert os.path.exists(wd) - # # Logging is redirected to a file with INFO level - # log_file = get_pytwin_log_file() - # logger = get_pytwin_logger() - # logger.debug("Hello 10") - # logger.info("Hello 20") - # logger.warning("Hello 30") - # logger.error("Hello 40") - # logger.critical("Hello 50") - # with open(log_file, "r") as f: - # lines = f.readlines() - # assert "Hello 10" not in lines - # assert len(lines) == 5 - # assert os.path.exists(log_file) - # assert len(logger.handlers) == 1 - # assert pytwin_logging_is_enabled() - # + def test_default_setting(self): + # Working directory is created in temp folder + wd = get_pytwin_working_dir() + assert tempfile.gettempdir() in wd + assert os.path.exists(wd) + # Logging is redirected to a file with INFO level + log_file = get_pytwin_log_file() + logger = get_pytwin_logger() + logger.debug("Hello 10") + logger.info("Hello 20") + logger.warning("Hello 30") + logger.error("Hello 40") + logger.critical("Hello 50") + with open(log_file, "r") as f: + lines = f.readlines() + print(lines) + assert "Hello 10" not in lines + assert len(lines) == 5 + assert os.path.exists(log_file) + assert len(logger.handlers) == 1 + assert pytwin_logging_is_enabled() + def test_modify_logging_raises_error(self): # Init unit test reinit_settings() From 9e59827b97568501e24e4c42721c39721b3dae39 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 12 Feb 2024 12:22:33 +0000 Subject: [PATCH 2/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_settings.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/test_settings.py b/tests/test_settings.py index 76edd146..16e4fc0d 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -1,6 +1,7 @@ import logging import os import shutil +import tempfile from pytwin import ( PyTwinLogLevel, @@ -14,9 +15,6 @@ pytwin_logging_is_enabled, ) -import tempfile - - UNIT_TEST_WD = os.path.join(os.path.dirname(__file__), "unit_test_wd") From aef51bc2242c24560371a07262006d98f3f1b922 Mon Sep 17 00:00:00 2001 From: chrpetre Date: Mon, 12 Feb 2024 13:28:24 +0100 Subject: [PATCH 3/8] Update test_settings.py --- tests/test_settings.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_settings.py b/tests/test_settings.py index 16e4fc0d..fa40fdd1 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -35,6 +35,9 @@ def test_default_setting(self): assert os.path.exists(wd) # Logging is redirected to a file with INFO level log_file = get_pytwin_log_file() + with open(log_file, "r") as f: + lines = f.readlines() + n_lines1 = len(lines) logger = get_pytwin_logger() logger.debug("Hello 10") logger.info("Hello 20") @@ -43,9 +46,9 @@ def test_default_setting(self): logger.critical("Hello 50") with open(log_file, "r") as f: lines = f.readlines() - print(lines) + n_lines2 = len(lines) assert "Hello 10" not in lines - assert len(lines) == 5 + assert n_lines2-n_lines1 == 4 # all the logger additions except debug assert os.path.exists(log_file) assert len(logger.handlers) == 1 assert pytwin_logging_is_enabled() From 66fce773dbf2c0a2817a835cd34a7f4d38d4e499 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 12 Feb 2024 12:29:01 +0000 Subject: [PATCH 4/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_settings.py b/tests/test_settings.py index fa40fdd1..807bd136 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -48,7 +48,7 @@ def test_default_setting(self): lines = f.readlines() n_lines2 = len(lines) assert "Hello 10" not in lines - assert n_lines2-n_lines1 == 4 # all the logger additions except debug + assert n_lines2 - n_lines1 == 4 # all the logger additions except debug assert os.path.exists(log_file) assert len(logger.handlers) == 1 assert pytwin_logging_is_enabled() From 1553754a0517a79cd455180ebebec53ab84c618d Mon Sep 17 00:00:00 2001 From: chrpetre Date: Mon, 12 Feb 2024 13:34:33 +0100 Subject: [PATCH 5/8] Update test_settings.py --- tests/test_settings.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tests/test_settings.py b/tests/test_settings.py index fa40fdd1..fcb1091c 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -207,21 +207,21 @@ def test_modify_working_dir_with_not_existing(self): assert os.path.exists(UNIT_TEST_WD) assert UNIT_TEST_WD == get_pytwin_working_dir() - # def test_modify_working_dir_with_existing_erase_false(self): - # # Init unit test - # reinit_settings() - # os.mkdir(UNIT_TEST_WD) - # with open(os.path.join(UNIT_TEST_WD, "test.txt"), "w") as f: - # pass - # assert len(os.listdir(UNIT_TEST_WD)) == 1 - # assert "test.txt" in os.listdir(UNIT_TEST_WD) - # # Existing dir with erase = false - # modify_pytwin_working_dir(new_path=UNIT_TEST_WD, erase=False) - # temp = os.listdir(UNIT_TEST_WD) - # assert len(os.listdir(UNIT_TEST_WD)) == 2 # test.txt + log file - # assert "test.txt" in os.listdir(UNIT_TEST_WD) - # assert os.path.split(get_pytwin_log_file())[-1] in os.listdir(UNIT_TEST_WD) - # + def test_modify_working_dir_with_existing_erase_false(self): + # Init unit test + reinit_settings() + os.mkdir(UNIT_TEST_WD) + with open(os.path.join(UNIT_TEST_WD, "test.txt"), "w") as f: + pass + assert len(os.listdir(UNIT_TEST_WD)) == 1 + assert "test.txt" in os.listdir(UNIT_TEST_WD) + # Existing dir with erase = false + modify_pytwin_working_dir(new_path=UNIT_TEST_WD, erase=False) + temp = os.listdir(UNIT_TEST_WD) + assert len(os.listdir(UNIT_TEST_WD)) == 2 # test.txt + log file + assert "test.txt" in os.listdir(UNIT_TEST_WD) + assert os.path.split(get_pytwin_log_file())[-1] in os.listdir(UNIT_TEST_WD) + # def test_modify_working_dir_with_existing_erase_true(self): # # Init unit test # reinit_settings() From 37bfaff4d15e8f9fea6b8d5ac71e7063be62d0fd Mon Sep 17 00:00:00 2001 From: chrpetre Date: Mon, 12 Feb 2024 14:54:43 +0100 Subject: [PATCH 6/8] Update test_settings.py --- tests/test_settings.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_settings.py b/tests/test_settings.py index 20e7affa..56a3c56e 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -215,11 +215,13 @@ def test_modify_working_dir_with_existing_erase_false(self): pass assert len(os.listdir(UNIT_TEST_WD)) == 1 assert "test.txt" in os.listdir(UNIT_TEST_WD) + assert "pytwin.log" not in os.listdir(UNIT_TEST_WD) # CP change # Existing dir with erase = false modify_pytwin_working_dir(new_path=UNIT_TEST_WD, erase=False) temp = os.listdir(UNIT_TEST_WD) - assert len(os.listdir(UNIT_TEST_WD)) == 2 # test.txt + log file + # assert len(os.listdir(UNIT_TEST_WD)) == 2 # test.txt + log file -> CP change as failing on Linux testing assert "test.txt" in os.listdir(UNIT_TEST_WD) + assert "pytwin.log" in os.listdir(UNIT_TEST_WD) # CP change assert os.path.split(get_pytwin_log_file())[-1] in os.listdir(UNIT_TEST_WD) # def test_modify_working_dir_with_existing_erase_true(self): From d243f5206001c981f21e43e171187943d21477bc Mon Sep 17 00:00:00 2001 From: chrpetre Date: Mon, 12 Feb 2024 14:57:50 +0100 Subject: [PATCH 7/8] Update test_settings.py --- tests/test_settings.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/tests/test_settings.py b/tests/test_settings.py index 56a3c56e..ddd1f8f5 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -224,21 +224,23 @@ def test_modify_working_dir_with_existing_erase_false(self): assert "pytwin.log" in os.listdir(UNIT_TEST_WD) # CP change assert os.path.split(get_pytwin_log_file())[-1] in os.listdir(UNIT_TEST_WD) - # def test_modify_working_dir_with_existing_erase_true(self): - # # Init unit test - # reinit_settings() - # os.mkdir(UNIT_TEST_WD) - # with open(os.path.join(UNIT_TEST_WD, "test.txt"), "w") as f: - # pass - # assert len(os.listdir(UNIT_TEST_WD)) == 1 - # assert "test.txt" in os.listdir(UNIT_TEST_WD) - # # Existing dir with erase = false - # modify_pytwin_working_dir(new_path=UNIT_TEST_WD, erase=True) - # temp = os.listdir(UNIT_TEST_WD) - # assert len(os.listdir(UNIT_TEST_WD)) == 1 # log file - # assert "test.txt" not in os.listdir(UNIT_TEST_WD) - # assert os.path.split(get_pytwin_log_file())[-1] in os.listdir(UNIT_TEST_WD) - # + def test_modify_working_dir_with_existing_erase_true(self): + # Init unit test + reinit_settings() + os.mkdir(UNIT_TEST_WD) + with open(os.path.join(UNIT_TEST_WD, "test.txt"), "w") as f: + pass + assert len(os.listdir(UNIT_TEST_WD)) == 1 + assert "test.txt" in os.listdir(UNIT_TEST_WD) + assert "pytwin.log" not in os.listdir(UNIT_TEST_WD) # CP change + # Existing dir with erase = false + modify_pytwin_working_dir(new_path=UNIT_TEST_WD, erase=True) + temp = os.listdir(UNIT_TEST_WD) + #assert len(os.listdir(UNIT_TEST_WD)) == 1 # log file -> CP change as failing on Linux testing + assert "test.txt" not in os.listdir(UNIT_TEST_WD) + assert "pytwin.log" in os.listdir(UNIT_TEST_WD) # CP change + assert os.path.split(get_pytwin_log_file())[-1] in os.listdir(UNIT_TEST_WD) + def test_modify_working_dir_migration(self): # Init unit test reinit_settings() From 892c2d0424c06f8ac51a8acb9be6e3e1304ccc26 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 12 Feb 2024 13:58:11 +0000 Subject: [PATCH 8/8] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/test_settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_settings.py b/tests/test_settings.py index ddd1f8f5..6a774f65 100644 --- a/tests/test_settings.py +++ b/tests/test_settings.py @@ -236,7 +236,7 @@ def test_modify_working_dir_with_existing_erase_true(self): # Existing dir with erase = false modify_pytwin_working_dir(new_path=UNIT_TEST_WD, erase=True) temp = os.listdir(UNIT_TEST_WD) - #assert len(os.listdir(UNIT_TEST_WD)) == 1 # log file -> CP change as failing on Linux testing + # assert len(os.listdir(UNIT_TEST_WD)) == 1 # log file -> CP change as failing on Linux testing assert "test.txt" not in os.listdir(UNIT_TEST_WD) assert "pytwin.log" in os.listdir(UNIT_TEST_WD) # CP change assert os.path.split(get_pytwin_log_file())[-1] in os.listdir(UNIT_TEST_WD)