From ea1fd1be11ffcd9a531547e38b2888ab819f81ec Mon Sep 17 00:00:00 2001 From: egberts Date: Tue, 23 Jul 2024 21:25:35 -0500 Subject: [PATCH] Add test_settings_syntax.py and supporting test data files in "unpythonized" format to skirt by the RUFF/Black format/linters. --- pelican/__init__.py | 3 +- .../pelicanconf-indent1-error.py.disabled | 4 +- .../pelicanconf-indent2-error.py.disabled | 10 +---- .../pelicanconf-syntax3-error.py.disabled | 6 +-- .../pelicanconf-syntax4-error.py.disabled | 14 ++++--- pelican/tests/test_settings_syntax.py | 40 +++++++++---------- 6 files changed, 38 insertions(+), 39 deletions(-) diff --git a/pelican/__init__.py b/pelican/__init__.py index 96849bae..becb9a43 100644 --- a/pelican/__init__.py +++ b/pelican/__init__.py @@ -15,7 +15,8 @@ from collections.abc import Iterable # locations in the file system (e.g. pip with `-e` or `--user`) from pkgutil import extend_path -__path__ = extend_path(__path__, __name__) +if "__path__" in globals(): + __path__ = extend_path(__path__, __name__) # pelican.log has to be the first pelican module to be loaded # because logging.setLoggerClass has to be called before logging.getLogger diff --git a/pelican/tests/settings/pelicanconf-indent1-error.py.disabled b/pelican/tests/settings/pelicanconf-indent1-error.py.disabled index 0bee3309..54fa90e4 100644 --- a/pelican/tests/settings/pelicanconf-indent1-error.py.disabled +++ b/pelican/tests/settings/pelicanconf-indent1-error.py.disabled @@ -2,12 +2,12 @@ # Error to occur is at line 13, column 5 # CAUTION: do not change this error location without corresponding changes in test cases -import me +import os def function_a(arg1): value2 = arg1 - value3 = value2 + 1 + value3 = value2 + 1 return value3 int i diff --git a/pelican/tests/settings/pelicanconf-indent2-error.py.disabled b/pelican/tests/settings/pelicanconf-indent2-error.py.disabled index 0bee3309..6e7c2385 100644 --- a/pelican/tests/settings/pelicanconf-indent2-error.py.disabled +++ b/pelican/tests/settings/pelicanconf-indent2-error.py.disabled @@ -1,14 +1,8 @@ #! Ohhhtay, this is not a python file despite it's .py file extension -# Error to occur is at line 13, column 5 -# CAUTION: do not change this error location without corresponding changes in test cases -import me +# Error to occur is at line 5, column 2 -def function_a(arg1): - - value2 = arg1 - value3 = value2 + 1 - return value3 + // put some C code in it int i diff --git a/pelican/tests/settings/pelicanconf-syntax3-error.py.disabled b/pelican/tests/settings/pelicanconf-syntax3-error.py.disabled index 0bee3309..23de3733 100644 --- a/pelican/tests/settings/pelicanconf-syntax3-error.py.disabled +++ b/pelican/tests/settings/pelicanconf-syntax3-error.py.disabled @@ -1,18 +1,18 @@ #! Ohhhtay, this is not a python file despite it's .py file extension -# Error to occur is at line 13, column 5 +# Error to occur is at line 9, column 29 # CAUTION: do not change this error location without corresponding changes in test cases import me def function_a(arg1): + value1 = [ 'a', 'b', 'c' } value2 = arg1 value3 = value2 + 1 return value3 -int i -for (i = 1; i < 200; ) { + for (i = 1; i < 200; ) { i = i + 1; } diff --git a/pelican/tests/settings/pelicanconf-syntax4-error.py.disabled b/pelican/tests/settings/pelicanconf-syntax4-error.py.disabled index 6e7c2385..609b1ad6 100644 --- a/pelican/tests/settings/pelicanconf-syntax4-error.py.disabled +++ b/pelican/tests/settings/pelicanconf-syntax4-error.py.disabled @@ -1,12 +1,16 @@ #! Ohhhtay, this is not a python file despite it's .py file extension +# Error to occur is at line 13, column 5 +# CAUTION: do not change this error location without corresponding changes in test cases -# Error to occur is at line 5, column 2 +import os - // put some C code in it +def function_a(arg1): -int i + value2 = arg1 + value3 = value2 + 1 + return value3 -for (i = 1; i < 200; ) { + for (i = 1; i < 200; ) { i = i + 1; - } + } diff --git a/pelican/tests/test_settings_syntax.py b/pelican/tests/test_settings_syntax.py index 804dc857..efdf53d6 100644 --- a/pelican/tests/test_settings_syntax.py +++ b/pelican/tests/test_settings_syntax.py @@ -64,14 +64,14 @@ BLOB_FULLNAME_SYNTAX3_ERROR = PC_FULLNAME_SYNTAX3_ERROR + EXT_PYTHON_DISABLED BLOB_FULLNAME_SYNTAX4_ERROR = PC_FULLNAME_SYNTAX4_ERROR + EXT_PYTHON_DISABLED # SyntaxError placement for use with settings/pelicanconf-syntax-error.py -SM_UT_SYNTAX_INDENT1_LINENO = 5 # tests/settings/pelicanconf-indent-error1.py.disabled -SM_UT_SYNTAX_INDENT1_OFFSET = 1 # tests/settings/pelicanconf-indent-error1.py.disabled -SM_UT_SYNTAX_INDENT2_LINENO = 13 # tests/settings/pelicanconf-indent-error2.py.disabled -SM_UT_SYNTAX_INDENT2_OFFSET = 5 # tests/settings/pelicanconf-indent-error2.py.disabled -SM_UT_SYNTAX_ERROR3_LINENO = 13 # tests/settings/pelicanconf-syntax-error3.py.disabled -SM_UT_SYNTAX_ERROR3_OFFSET = 5 # tests/settings/pelicanconf-syntax-error3.py.disabled -SM_UT_SYNTAX_ERROR4_LINENO = 5 # tests/settings/pelicanconf-syntax-error4.py.disabled -SM_UT_SYNTAX_ERROR4_OFFSET = 1 # tests/settings/pelicanconf-syntax-error4.py.disabled +SM_UT_SYNTAX_INDENT1_LINENO = 10 # tests/settings/pelicanconf-indent-error1.py.disabled +SM_UT_SYNTAX_INDENT1_OFFSET = 7 # tests/settings/pelicanconf-indent-error1.py.disabled +SM_UT_SYNTAX_INDENT2_LINENO = 5 # tests/settings/pelicanconf-indent-error2.py.disabled +SM_UT_SYNTAX_INDENT2_OFFSET = 1 # tests/settings/pelicanconf-indent-error2.py.disabled +SM_UT_SYNTAX_ERROR3_LINENO = 9 # tests/settings/pelicanconf-syntax-error3.py.disabled +SM_UT_SYNTAX_ERROR3_OFFSET = 30 # tests/settings/pelicanconf-syntax-error3.py.disabled +SM_UT_SYNTAX_ERROR4_LINENO = 13 # tests/settings/pelicanconf-syntax-error4.py.disabled +SM_UT_SYNTAX_ERROR4_OFFSET = 10 # tests/settings/pelicanconf-syntax-error4.py.disabled load_source_argument_list_count = 2 @@ -319,10 +319,10 @@ class TestSettingsSyntax: with self._caplog.at_level(logging.DEBUG): self._caplog.clear() - with pytest.raises(SyntaxError) as sample: + with pytest.raises(IndentationError) as sample: # ignore return value due to sys.exit() load_source(default_module, str(indent_error_file)) - assert sample.type == SyntaxError + assert sample.type == IndentationError # TODO Issue #09005 - say something to the end-user exactly where syntax err is # assert "unexpected indent" in self._caplog.text @@ -356,10 +356,10 @@ class TestSettingsSyntax: with self._caplog.at_level(logging.DEBUG): self._caplog.clear() - with pytest.raises(SyntaxError) as sample: + with pytest.raises(IndentationError) as sample: # ignore return value due to sys.exit() load_source(default_module, str(indent_error_file)) - assert sample.type == SyntaxError + assert sample.type == IndentationError # TODO Issue #09005 - say something to the end-user exactly where syntax err is # assert "unexpected indent" in self._caplog.text @@ -393,10 +393,10 @@ class TestSettingsSyntax: with self._caplog.at_level(logging.DEBUG): self._caplog.clear() - with pytest.raises(SyntaxError) as sample: + with pytest.raises(IndentationError) as sample: # ignore return value due to sys.exit() load_source(default_module, str(indent_error_file)) - assert sample.type == SyntaxError + assert sample.type == IndentationError # TODO Issue #09005 - say something to the end-user exactly where syntax err is # assert "unexpected indent" in self._caplog.text @@ -430,10 +430,10 @@ class TestSettingsSyntax: with self._caplog.at_level(logging.DEBUG): self._caplog.clear() - with pytest.raises(SyntaxError) as sample: + with pytest.raises(IndentationError) as sample: # ignore return value due to sys.exit() load_source(default_module, str(indent_error_file)) - assert sample.type == SyntaxError + assert sample.type == IndentationError # TODO Issue #09005 - say something to the end-user exactly where syntax err is # assert "unexpected indent" in self._caplog.text @@ -466,10 +466,10 @@ class TestSettingsSyntax: with self._caplog.at_level(logging.DEBUG): self._caplog.clear() - with pytest.raises(SyntaxError) as sample: + with pytest.raises(IndentationError) as sample: # ignore return value due to sys.exit() load_source(default_module, str(indent_error_file)) - assert sample.type == SyntaxError + assert sample.type == IndentationError # TODO Issue #09005 - say something to the end-user exactly where syntax err is # assert "unexpected indent" in self._caplog.text @@ -503,11 +503,11 @@ class TestSettingsSyntax: with self._caplog.at_level(logging.DEBUG): self._caplog.clear() - with pytest.raises(SyntaxError) as sample: + with pytest.raises(IndentationError) as sample: # ignore return value due to sys.exit() load_source(indent_error_module, path=str(indent_error_file)) - assert sample.type == SyntaxError + assert sample.type == IndentationError assert sample.value.lineno == SM_UT_SYNTAX_INDENT2_LINENO assert sample.value.offset == SM_UT_SYNTAX_INDENT2_OFFSET # Would be nice if a STDERR says something to end-user WHERE