From 385b5b9f2394463784d5d13a9d38ba36b8f8c28c Mon Sep 17 00:00:00 2001 From: Haoyu Yang Date: Sat, 30 Mar 2024 17:34:29 +0800 Subject: [PATCH 01/12] replace `raise` for warning with `warn` explicitly check for None fix string format in `test_io` add missing f for format string fix date format fix datetime in string DEBUG: comment out no warn case 3 DEBUG: comment out no warn case 2 DEBUG: comment out no warn case try to fix warning fix time patch try to fix date patch revert to monkeypatch --- monty/dev.py | 16 +++++++++------- tests/test_dev.py | 9 +++------ tests/test_io.py | 8 ++------ 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/monty/dev.py b/monty/dev.py index 35993307..fccfc010 100644 --- a/monty/dev.py +++ b/monty/dev.py @@ -72,12 +72,13 @@ def _is_in_owner_repo() -> bool: # Only raise warning in code owner's repo CI if ( _deadline is not None - and os.getenv("CI") + and os.getenv("CI") is not None and datetime.now() > _deadline and _is_in_owner_repo() ): - raise DeprecationWarning( - "This function should have been removed on {deadline:%Y-%m-%d}." + warnings.warn( + f"This function should have been removed on {_deadline:%Y-%m-%d}.", + DeprecationWarning, ) def craft_message( @@ -89,7 +90,7 @@ def craft_message( msg = f"{old.__name__} is deprecated" if deadline is not None: - msg += f", and will be removed on {deadline:%Y-%m-%d}\n" + msg += f", and will be removed on {_deadline:%Y-%m-%d}\n" if replacement is not None: if isinstance(replacement, property): @@ -108,6 +109,10 @@ def deprecated_decorator(old: Callable): def wrapped(*args, **kwargs): msg = craft_message(old, replacement, message, _deadline) warnings.warn(msg, category=category, stacklevel=2) + + # Raise a CI warning after removal deadline + raise_deadline_warning() + return old(*args, **kwargs) return wrapped @@ -115,9 +120,6 @@ def wrapped(*args, **kwargs): # Convert deadline to datetime type _deadline = datetime(*deadline) if deadline is not None else None - # Raise a CI warning after removal deadline - raise_deadline_warning() - return deprecated_decorator diff --git a/tests/test_dev.py b/tests/test_dev.py index 6b9816a7..610c089b 100644 --- a/tests/test_dev.py +++ b/tests/test_dev.py @@ -94,9 +94,8 @@ def func_old(): pass with warnings.catch_warnings(record=True) as warn_msgs: - # Trigger a warning. - func_old() - # Verify message + func_old() # trigger a warning + assert "will be removed on 2000-01-01" in str(warn_msgs[0].message) def test_deprecated_deadline_no_warn(self, monkeypatch): @@ -108,9 +107,7 @@ def func_old(): # No warn case 1: date before deadline with warnings.catch_warnings(record=True) as warn_msgs: - monkeypatch.setattr( - datetime, "datetime", lambda: datetime.datetime(1999, 1, 1) - ) + monkeypatch.setattr(datetime, "datetime", datetime.datetime(1999, 1, 1)) func_old() for warning in warn_msgs: diff --git a/tests/test_io.py b/tests/test_io.py index 043e6744..2aa67611 100644 --- a/tests/test_io.py +++ b/tests/test_io.py @@ -32,9 +32,7 @@ def test_reverse_readline(self): for idx, line in enumerate(reverse_readline(f)): assert ( int(line) == self.NUMLINES - idx - ), "read_backwards read {} whereas it should "( - "have read {" "}" - ).format(int(line), self.NUMLINES - idx) + ), f"read_backwards read {int(line)} whereas it should have read {self.NUMLINES - idx}" def test_reverse_readline_fake_big(self): """ @@ -44,9 +42,7 @@ def test_reverse_readline_fake_big(self): for idx, line in enumerate(reverse_readline(f, max_mem=0)): assert ( int(line) == self.NUMLINES - idx - ), "read_backwards read {} whereas it should "( - "have read {" "}" - ).format(int(line), self.NUMLINES - idx) + ), f"read_backwards read {int(line)} whereas it should have read {self.NUMLINES - idx}" def test_reverse_readline_bz2(self): """ From 49d51de9e2ea01bbd99842add09e7ea5ad939b60 Mon Sep 17 00:00:00 2001 From: Haoyu Yang Date: Sun, 31 Mar 2024 16:43:58 +0800 Subject: [PATCH 02/12] adjust warn position --- monty/dev.py | 7 +++---- tests/test_dev.py | 41 +++++++++++++++++++++++------------------ 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/monty/dev.py b/monty/dev.py index fccfc010..6b0c22d7 100644 --- a/monty/dev.py +++ b/monty/dev.py @@ -109,10 +109,6 @@ def deprecated_decorator(old: Callable): def wrapped(*args, **kwargs): msg = craft_message(old, replacement, message, _deadline) warnings.warn(msg, category=category, stacklevel=2) - - # Raise a CI warning after removal deadline - raise_deadline_warning() - return old(*args, **kwargs) return wrapped @@ -120,6 +116,9 @@ def wrapped(*args, **kwargs): # Convert deadline to datetime type _deadline = datetime(*deadline) if deadline is not None else None + # Raise CI warning after removal deadline + raise_deadline_warning() + return deprecated_decorator diff --git a/tests/test_dev.py b/tests/test_dev.py index 610c089b..e0db969e 100644 --- a/tests/test_dev.py +++ b/tests/test_dev.py @@ -89,36 +89,38 @@ def classmethod_b(cls): assert TestClass_deprecationwarning().classmethod_b() == "b" def test_deprecated_deadline(self): - @deprecated(deadline=(2000, 1, 1)) - def func_old(): - pass with warnings.catch_warnings(record=True) as warn_msgs: - func_old() # trigger a warning + @deprecated(deadline=(2000, 1, 1)) + def func_old(): + pass - assert "will be removed on 2000-01-01" in str(warn_msgs[0].message) + assert "This function should have been removed" in str(warn_msgs[0].message) def test_deprecated_deadline_no_warn(self, monkeypatch): """Test cases where no warning should be raised.""" - @deprecated(deadline=(2000, 1, 1)) - def func_old(): - pass + # # No warn case 1: date before deadline + # DEBUG + # with warnings.catch_warnings(record=True) as warn_msgs: + # monkeypatch.setattr(datetime.datetime, "now", datetime.datetime(1999, 1, 1)) - # No warn case 1: date before deadline - with warnings.catch_warnings(record=True) as warn_msgs: - monkeypatch.setattr(datetime, "datetime", datetime.datetime(1999, 1, 1)) - func_old() + # @deprecated(deadline=(2000, 1, 1)) + # def func_old(): + # pass - for warning in warn_msgs: - assert "This function should have been removed on" not in str( - warning.message - ) + # for warning in warn_msgs: + # assert "This function should have been removed on" not in str( + # warning.message + # ) # No warn case 2: not in CI env with warnings.catch_warnings(record=True) as warn_msgs: monkeypatch.delenv("CI", raising=False) - func_old() + + @deprecated(deadline=(2000, 1, 1)) + def func_old(): + pass for warning in warn_msgs: assert "This function should have been removed on" not in str( @@ -128,7 +130,10 @@ def func_old(): # No warn case 3: not in code owner repo with warnings.catch_warnings(record=True) as warn_msgs: monkeypatch.setenv("GITHUB_REPOSITORY", "NONE/NONE") - func_old() + + @deprecated(deadline=(2000, 1, 1)) + def func_old(): + pass for warning in warn_msgs: assert "This function should have been removed on" not in str( From 12a646d602e8f078212a9ccb6970253c111bd201 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 31 Mar 2024 08:44:11 +0000 Subject: [PATCH 03/12] pre-commit auto-fixes --- tests/test_dev.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_dev.py b/tests/test_dev.py index e0db969e..f036b76a 100644 --- a/tests/test_dev.py +++ b/tests/test_dev.py @@ -1,6 +1,5 @@ import unittest import warnings -import datetime import pytest from monty.dev import deprecated, install_excepthook, requires @@ -89,8 +88,8 @@ def classmethod_b(cls): assert TestClass_deprecationwarning().classmethod_b() == "b" def test_deprecated_deadline(self): - with warnings.catch_warnings(record=True) as warn_msgs: + @deprecated(deadline=(2000, 1, 1)) def func_old(): pass From 1998adb90c7b99e43b9b1ae706a03f5dc4996c98 Mon Sep 17 00:00:00 2001 From: Haoyu Yang Date: Sun, 31 Mar 2024 20:08:22 +0800 Subject: [PATCH 04/12] fix datetime.now patch --- tests/test_dev.py | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/tests/test_dev.py b/tests/test_dev.py index e0db969e..0b366f89 100644 --- a/tests/test_dev.py +++ b/tests/test_dev.py @@ -1,6 +1,7 @@ import unittest import warnings import datetime +from unittest.mock import MagicMock import pytest from monty.dev import deprecated, install_excepthook, requires @@ -88,9 +89,12 @@ def classmethod_b(cls): with pytest.warns(DeprecationWarning): assert TestClass_deprecationwarning().classmethod_b() == "b" - def test_deprecated_deadline(self): - + @pytest.mark.skip() + def test_deprecated_deadline(self, monkeypatch): with warnings.catch_warnings(record=True) as warn_msgs: + monkeypatch.setenv("CI", "true") + monkeypatch.setenv("GITHUB_REPOSITORY", "materialsvirtuallab/monty") + @deprecated(deadline=(2000, 1, 1)) def func_old(): pass @@ -100,26 +104,28 @@ def func_old(): def test_deprecated_deadline_no_warn(self, monkeypatch): """Test cases where no warning should be raised.""" - # # No warn case 1: date before deadline - # DEBUG - # with warnings.catch_warnings(record=True) as warn_msgs: - # monkeypatch.setattr(datetime.datetime, "now", datetime.datetime(1999, 1, 1)) + # No warn case 1: date before deadline + with warnings.catch_warnings(record=True) as warn_msgs: + # Mock date to 1999-01-01 + datetime_mock = MagicMock(wrap=datetime.datetime) + datetime_mock.now.return_value = datetime.datetime(1999, 1, 1) + monkeypatch.setattr(datetime, "datetime", datetime_mock) - # @deprecated(deadline=(2000, 1, 1)) - # def func_old(): - # pass + @deprecated(deadline=(2000, 1, 1)) + def func_old_0(): + pass - # for warning in warn_msgs: - # assert "This function should have been removed on" not in str( - # warning.message - # ) + for warning in warn_msgs: + assert "This function should have been removed on" not in str( + warning.message + ) # No warn case 2: not in CI env with warnings.catch_warnings(record=True) as warn_msgs: monkeypatch.delenv("CI", raising=False) @deprecated(deadline=(2000, 1, 1)) - def func_old(): + def func_old_1(): pass for warning in warn_msgs: @@ -132,7 +138,7 @@ def func_old(): monkeypatch.setenv("GITHUB_REPOSITORY", "NONE/NONE") @deprecated(deadline=(2000, 1, 1)) - def func_old(): + def func_old_2(): pass for warning in warn_msgs: From 07d52f3274fc686566dc52626f22ade02e66751b Mon Sep 17 00:00:00 2001 From: Haoyu Yang Date: Sun, 31 Mar 2024 20:11:15 +0800 Subject: [PATCH 05/12] revert to `raise` for `DeprecationWarning` --- monty/dev.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/monty/dev.py b/monty/dev.py index 6b0c22d7..241b912e 100644 --- a/monty/dev.py +++ b/monty/dev.py @@ -76,9 +76,8 @@ def _is_in_owner_repo() -> bool: and datetime.now() > _deadline and _is_in_owner_repo() ): - warnings.warn( - f"This function should have been removed on {_deadline:%Y-%m-%d}.", - DeprecationWarning, + raise DeprecationWarning( + f"This function should have been removed on {_deadline:%Y-%m-%d}." ) def craft_message( From 890ed14f7b155d49c572e1b18d7bea0184354877 Mon Sep 17 00:00:00 2001 From: Haoyu Yang Date: Sun, 31 Mar 2024 20:31:31 +0800 Subject: [PATCH 06/12] temp fix for "should raise" case --- tests/test_dev.py | 28 +++++----------------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/tests/test_dev.py b/tests/test_dev.py index 0b366f89..90326932 100644 --- a/tests/test_dev.py +++ b/tests/test_dev.py @@ -89,9 +89,8 @@ def classmethod_b(cls): with pytest.warns(DeprecationWarning): assert TestClass_deprecationwarning().classmethod_b() == "b" - @pytest.mark.skip() def test_deprecated_deadline(self, monkeypatch): - with warnings.catch_warnings(record=True) as warn_msgs: + with pytest.raises(DeprecationWarning): monkeypatch.setenv("CI", "true") monkeypatch.setenv("GITHUB_REPOSITORY", "materialsvirtuallab/monty") @@ -99,13 +98,11 @@ def test_deprecated_deadline(self, monkeypatch): def func_old(): pass - assert "This function should have been removed" in str(warn_msgs[0].message) - def test_deprecated_deadline_no_warn(self, monkeypatch): """Test cases where no warning should be raised.""" # No warn case 1: date before deadline - with warnings.catch_warnings(record=True) as warn_msgs: + with warnings.catch_warnings(): # Mock date to 1999-01-01 datetime_mock = MagicMock(wrap=datetime.datetime) datetime_mock.now.return_value = datetime.datetime(1999, 1, 1) @@ -115,37 +112,22 @@ def test_deprecated_deadline_no_warn(self, monkeypatch): def func_old_0(): pass - for warning in warn_msgs: - assert "This function should have been removed on" not in str( - warning.message - ) - # No warn case 2: not in CI env - with warnings.catch_warnings(record=True) as warn_msgs: + with warnings.catch_warnings(): monkeypatch.delenv("CI", raising=False) @deprecated(deadline=(2000, 1, 1)) def func_old_1(): pass - for warning in warn_msgs: - assert "This function should have been removed on" not in str( - warning.message - ) - # No warn case 3: not in code owner repo - with warnings.catch_warnings(record=True) as warn_msgs: - monkeypatch.setenv("GITHUB_REPOSITORY", "NONE/NONE") + with warnings.catch_warnings(): + monkeypatch.delenv("GITHUB_REPOSITORY", raising=False) @deprecated(deadline=(2000, 1, 1)) def func_old_2(): pass - for warning in warn_msgs: - assert "This function should have been removed on" not in str( - warning.message - ) - def test_requires(self): try: import fictitious_mod # type: ignore From 4ea8d1bb7db1cf0f29f0fa0f097d686eb6a97638 Mon Sep 17 00:00:00 2001 From: Haoyu Yang Date: Sun, 31 Mar 2024 20:36:50 +0800 Subject: [PATCH 07/12] add `ipython` to optional requirements --- requirements-optional.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements-optional.txt b/requirements-optional.txt index f94a7fa4..ccdfc7d6 100644 --- a/requirements-optional.txt +++ b/requirements-optional.txt @@ -7,3 +7,4 @@ pandas==2.2.1 orjson==3.9.15 types-orjson==3.6.2 types-requests==2.31.0.20240218 +ipython==8.22.2 From 5da8026c9bce39db6bf90cdbd14c78f64c0ea7e6 Mon Sep 17 00:00:00 2001 From: Haoyu Yang Date: Sun, 31 Mar 2024 20:43:02 +0800 Subject: [PATCH 08/12] remove accidentially commited files --- tests/test_files/3000_lines.txt.gz | Bin 6496 -> 0 bytes venv/pyvenv.cfg | 3 -- venv/share/man/man1/ipython.1 | 60 ----------------------------- 3 files changed, 63 deletions(-) delete mode 100644 tests/test_files/3000_lines.txt.gz delete mode 100644 venv/pyvenv.cfg delete mode 100644 venv/share/man/man1/ipython.1 diff --git a/tests/test_files/3000_lines.txt.gz b/tests/test_files/3000_lines.txt.gz deleted file mode 100644 index e58423003e61f5de71db9505a3de26f97aa2a991..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6496 zcmdT^cU%+c(+5t^=qi=6{85K9H<~&k)~8Zlrv=&b7ET{Bzr1Y z5rcv!0($t16^w`&qJS45pdiu$N_*p}cUay(?){a|@BPdl&+I%i-|x&bv!l-;5QMJd z{Z&S0+S=Osga&Qf5@{V36QyD#U9wqrkvK+7bNvn2uF{b-eM`FHp}yuePOoRhjr;?z ziqhmUX^9Cg6$W!|a-$m^BlKer6uT(69Su&mRmZ(*a4gc`?djX7pCEEfJM7!*9HINl z@k!!2xo1bdB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k5okBTg-boIr**PhRt_3baw+>CnR zJKD8+;UG;~FC3-~)Q^na?mXS1;oscCr`?5S|7MC06Zcfu=gb)qzI8r3A{=nOHzFKz zel;>Ol;phWU%6%ugbhP?{^@c1zYS~sV6|vaA{u-y8hjxdY!VH&iU!+7gPo$mUeQRU Sb90Atg?^RZT>@;cqVhk8G>U%! diff --git a/venv/pyvenv.cfg b/venv/pyvenv.cfg deleted file mode 100644 index 0537ffc0..00000000 --- a/venv/pyvenv.cfg +++ /dev/null @@ -1,3 +0,0 @@ -home = /usr/bin -include-system-site-packages = false -version = 3.10.12 diff --git a/venv/share/man/man1/ipython.1 b/venv/share/man/man1/ipython.1 deleted file mode 100644 index 0f4a191f..00000000 --- a/venv/share/man/man1/ipython.1 +++ /dev/null @@ -1,60 +0,0 @@ -.\" Hey, EMACS: -*- nroff -*- -.\" First parameter, NAME, should be all caps -.\" Second parameter, SECTION, should be 1-8, maybe w/ subsection -.\" other parameters are allowed: see man(7), man(1) -.TH IPYTHON 1 "July 15, 2011" -.\" Please adjust this date whenever revising the manpage. -.\" -.\" Some roff macros, for reference: -.\" .nh disable hyphenation -.\" .hy enable hyphenation -.\" .ad l left justify -.\" .ad b justify to both left and right margins -.\" .nf disable filling -.\" .fi enable filling -.\" .br insert line break -.\" .sp insert n+1 empty lines -.\" for manpage-specific macros, see man(7) and groff_man(7) -.\" .SH section heading -.\" .SS secondary section heading -.\" -.\" -.\" To preview this page as plain text: nroff -man ipython.1 -.\" -.SH NAME -ipython \- Tools for Interactive Computing in Python. -.SH SYNOPSIS -.B ipython -.RI [ options ] " files" ... - -.B ipython subcommand -.RI [ options ] ... - -.SH DESCRIPTION -An interactive Python shell with automatic history (input and output), dynamic -object introspection, easier configuration, command completion, access to the -system shell, integration with numerical and scientific computing tools, -web notebook, Qt console, and more. - -For more information on how to use IPython, see 'ipython \-\-help', -or 'ipython \-\-help\-all' for all available command\(hyline options. - -.SH "ENVIRONMENT VARIABLES" -.sp -.PP -\fIIPYTHONDIR\fR -.RS 4 -This is the location where IPython stores all its configuration files. The default -is $HOME/.ipython if IPYTHONDIR is not defined. - -You can see the computed value of IPYTHONDIR with `ipython locate`. - -.SH FILES - -IPython uses various configuration files stored in profiles within IPYTHONDIR. -To generate the default configuration files and start configuring IPython, -do 'ipython profile create', and edit '*_config.py' files located in -IPYTHONDIR/profile_default. - -.SH AUTHORS -IPython is written by the IPython Development Team . From d69055a080a093b493b014b5c224a1a70b51f880 Mon Sep 17 00:00:00 2001 From: Haoyu Yang Date: Sun, 31 Mar 2024 20:45:27 +0800 Subject: [PATCH 09/12] add test file back --- tests/test_files/3000_lines.txt.gz | Bin 0 -> 6496 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/test_files/3000_lines.txt.gz diff --git a/tests/test_files/3000_lines.txt.gz b/tests/test_files/3000_lines.txt.gz new file mode 100644 index 0000000000000000000000000000000000000000..25cd7bac5914729c80453443492cf45dfb765bf1 GIT binary patch literal 6496 zcmdT^dt6NG*RKx89A~HY+$3Gt-R~hu8oBJPam|nlokHnOy3tjMj=5|yN5ZbAnSD@h zB~!|g!r?crWh9w~%IPviNw+Dwz2o3WynmecclrF@&-&w8dp&D?ziT~f?WM~h5UyUo zx>adpmbJCDS8%}gt>KmtQ4vZ8(xqD(E)d6wY0kd`JCr&SW^7HBKh#y<&gpe8zn*{a zRdI?eDkVP7sa$XF4Q^zkeVA_a!4fAqx1-+Sw(^8m_4dVTyuE#!bmK(!DM!3}9mBL= z**}RtCv)$}m*15{;VUk zqha`<%z>w+CK4W$+4F`w;t$Gbym*JYPM#>ep((1m(^C|y8#2;SBD#{&H%}hjrj_oU z=j|mbO&QXN z)$m>!WEW+4hR0O2BH42?JtJePTer$O{rIw&y4K|EIXutk7+LGd>>{3LY)nV=(B{_5 zp7Ak#txefQS)K_oBLRs83$SU@tTVizWShk`(^a`?^tC4}9%%#|h#T&I+g+`DP0pwJ ztJUoNbW9uO%ROQr>J&_9U-;)S>@e^h%~4E~RTMZr9(E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00001 From bcc50019cd101458f0dc211d70a1e1c143b1e700 Mon Sep 17 00:00:00 2001 From: Haoyu Yang Date: Mon, 1 Apr 2024 10:30:13 +0800 Subject: [PATCH 10/12] mock GITHUB_REPOSITORY --- tests/test_dev.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/tests/test_dev.py b/tests/test_dev.py index 90326932..fa84f955 100644 --- a/tests/test_dev.py +++ b/tests/test_dev.py @@ -1,7 +1,7 @@ import unittest import warnings import datetime -from unittest.mock import MagicMock +from unittest.mock import MagicMock, patch import pytest from monty.dev import deprecated, install_excepthook, requires @@ -91,12 +91,18 @@ def classmethod_b(cls): def test_deprecated_deadline(self, monkeypatch): with pytest.raises(DeprecationWarning): - monkeypatch.setenv("CI", "true") - monkeypatch.setenv("GITHUB_REPOSITORY", "materialsvirtuallab/monty") - - @deprecated(deadline=(2000, 1, 1)) - def func_old(): - pass + monkeypatch.setenv("CI", "true") # mock CI env + + with patch("subprocess.run") as mock_run: + # Mock "GITHUB_REPOSITORY" + monkeypatch.setenv("GITHUB_REPOSITORY", "TESTOWNER/TESTREPO") + mock_run.return_value.stdout.decode.return_value = ( + "git@github.com:TESTOWNER/TESTREPO.git" + ) + + @deprecated(deadline=(2000, 1, 1)) + def func_old(): + pass def test_deprecated_deadline_no_warn(self, monkeypatch): """Test cases where no warning should be raised.""" From fadaf1461da1b6d3ba5d5f39a37df582a0471fe9 Mon Sep 17 00:00:00 2001 From: Haoyu Yang Date: Mon, 1 Apr 2024 10:47:44 +0800 Subject: [PATCH 11/12] refine unit test for deadline --- tests/test_dev.py | 50 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/tests/test_dev.py b/tests/test_dev.py index fa84f955..8a13c012 100644 --- a/tests/test_dev.py +++ b/tests/test_dev.py @@ -1,7 +1,7 @@ import unittest import warnings import datetime -from unittest.mock import MagicMock, patch +from unittest.mock import patch import pytest from monty.dev import deprecated, install_excepthook, requires @@ -91,9 +91,9 @@ def classmethod_b(cls): def test_deprecated_deadline(self, monkeypatch): with pytest.raises(DeprecationWarning): - monkeypatch.setenv("CI", "true") # mock CI env - with patch("subprocess.run") as mock_run: + monkeypatch.setenv("CI", "true") # mock CI env + # Mock "GITHUB_REPOSITORY" monkeypatch.setenv("GITHUB_REPOSITORY", "TESTOWNER/TESTREPO") mock_run.return_value.stdout.decode.return_value = ( @@ -104,30 +104,52 @@ def test_deprecated_deadline(self, monkeypatch): def func_old(): pass + @pytest.fixture() def test_deprecated_deadline_no_warn(self, monkeypatch): """Test cases where no warning should be raised.""" # No warn case 1: date before deadline with warnings.catch_warnings(): - # Mock date to 1999-01-01 - datetime_mock = MagicMock(wrap=datetime.datetime) - datetime_mock.now.return_value = datetime.datetime(1999, 1, 1) - monkeypatch.setattr(datetime, "datetime", datetime_mock) + with patch("subprocess.run") as mock_run: + monkeypatch.setenv("CI", "true") # mock CI env - @deprecated(deadline=(2000, 1, 1)) - def func_old_0(): - pass + # Mock date to 1999-01-01 + monkeypatch.setattr( + datetime.datetime, "now", datetime.datetime(1999, 1, 1) + ) + + # Mock "GITHUB_REPOSITORY" + monkeypatch.setenv("GITHUB_REPOSITORY", "TESTOWNER/TESTREPO") + mock_run.return_value.stdout.decode.return_value = ( + "git@github.com:TESTOWNER/TESTREPO.git" + ) + + @deprecated(deadline=(2000, 1, 1)) + def func_old(): + pass + + monkeypatch.undo() # No warn case 2: not in CI env with warnings.catch_warnings(): - monkeypatch.delenv("CI", raising=False) + with patch("subprocess.run") as mock_run: + monkeypatch.delenv("CI", raising=False) - @deprecated(deadline=(2000, 1, 1)) - def func_old_1(): - pass + # Mock "GITHUB_REPOSITORY" + monkeypatch.setenv("GITHUB_REPOSITORY", "TESTOWNER/TESTREPO") + mock_run.return_value.stdout.decode.return_value = ( + "git@github.com:TESTOWNER/TESTREPO.git" + ) + + @deprecated(deadline=(2000, 1, 1)) + def func_old_1(): + pass + + monkeypatch.undo() # No warn case 3: not in code owner repo with warnings.catch_warnings(): + monkeypatch.setenv("CI", "true") monkeypatch.delenv("GITHUB_REPOSITORY", raising=False) @deprecated(deadline=(2000, 1, 1)) From 5e589095d30557cfab19c99bb9952a610c9769ee Mon Sep 17 00:00:00 2001 From: Haoyu Yang Date: Mon, 1 Apr 2024 11:05:39 +0800 Subject: [PATCH 12/12] remove `unittest.main()` --- tests/test_tempfile.py | 5 ----- tests/test_termcolor.py | 5 ----- 2 files changed, 10 deletions(-) diff --git a/tests/test_tempfile.py b/tests/test_tempfile.py index ac57a20d..80372f3b 100644 --- a/tests/test_tempfile.py +++ b/tests/test_tempfile.py @@ -1,6 +1,5 @@ import os import shutil -import unittest from monty.tempfile import ScratchDir @@ -142,7 +141,3 @@ def test_bad_root(self): def teardown_method(self): os.chdir(self.cwd) shutil.rmtree(self.scratch_root) - - -if __name__ == "__main__": - unittest.main() diff --git a/tests/test_termcolor.py b/tests/test_termcolor.py index a57f0c55..843e2544 100644 --- a/tests/test_termcolor.py +++ b/tests/test_termcolor.py @@ -4,7 +4,6 @@ import os import sys -import unittest from monty.termcolor import ( cprint, @@ -75,7 +74,3 @@ def test_remove_non_ascii(self): def test_stream_has_colors(self): # TODO: not a real test. Need to do a proper test. stream_has_colours(sys.stdout) - - -if __name__ == "__main__": - unittest.main()