Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
Merge branch 'py10' of https://github.com/sdpython/pyensae into py10
Browse files Browse the repository at this point in the history
  • Loading branch information
sdpython committed Jul 25, 2022
2 parents a7704d3 + 9999b68 commit ef9f6a8
Show file tree
Hide file tree
Showing 38 changed files with 11,624 additions and 10,220 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -51,6 +51,7 @@ x64/
build/
[Bb]in/
[Oo]bj/
.eggs/

# MSTest test Results
[Tt]est[Rr]esult*/
Expand Down
66 changes: 16 additions & 50 deletions _unittests/ut_languages/test_parse_code.py
Expand Up @@ -7,38 +7,38 @@
import os
import unittest
import warnings
from pyquickhelper.loghelper import fLOG
from pyquickhelper.pycode import ExtTestCase


class TestParseCode(unittest.TestCase):
class TestParseCode(ExtTestCase):

def test_build_parser(self):
from pyensae.languages.antlr_grammar_use import (
get_parser_lexer, get_tree_string, parse_code)
from pyensae.languages.antlr_grammar_build import build_grammar
import pyensae.languages.antlr_grammar_use as source_parser

fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

langs = ["DOT", "CSharp4", "SQLite", "R"] # , "Python3"]

try:
for lang in langs:
get_parser_lexer(lang)
return
except ImportError:
pass
for lang in langs:
with self.subTest(lang=lang):
try:
get_parser_lexer(lang)
return
except ImportError:
pass

folder = os.path.dirname(source_parser.__file__)

rows = []

def local_print(*s):
rows.append(' '.join(map(str, s)))

for lang in langs:
fLOG("generate for LANG", lang)
gr = os.path.join(folder, lang + ".g4")
assert os.path.exists(gr)
final = build_grammar(lang, fLOG=fLOG)
final = build_grammar(lang, fLOG=local_print)
fLOG(final)

def test_r(self):
Expand All @@ -47,11 +47,6 @@ def test_r(self):
from pyensae.languages.antlr_grammar_build import build_grammar
import pyensae.languages.antlr_grammar_use as source_parser

fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

code = """
a = 4 ;
b = 5 ;
Expand All @@ -64,7 +59,6 @@ def test_r(self):
st = get_tree_string(tree, parser)
assert len(st) > 0
st = get_tree_string(tree, parser, None)
fLOG(st.replace("\\n", "\n"))
assert len(st) > 0

def test_sql(self):
Expand All @@ -73,11 +67,6 @@ def test_sql(self):
from pyensae.languages.antlr_grammar_build import build_grammar
import pyensae.languages.antlr_grammar_use as source_parser

fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

code = """
SELECT a,tbl.b,nb FROM tbl
INNER JOIN (
Expand All @@ -90,7 +79,6 @@ def test_sql(self):
parser = parse_code(code, clparser, cllexer)
tree = parser.parse()
st = get_tree_string(tree, parser, None)
fLOG(st.replace("\\n", "\n"))
assert len(st) > 0

def test_error(self):
Expand All @@ -99,11 +87,6 @@ def test_error(self):
from pyensae.languages.antlr_grammar_build import build_grammar
import pyensae.languages.antlr_grammar_use as source_parser

fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

code = """
SELECT
a,
Expand All @@ -126,11 +109,6 @@ def test_csharp(self):
from pyensae.languages.antlr_grammar_build import build_grammar
import pyensae.languages.antlr_grammar_use as source_parser

fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

code = """
namespace hello
{
Expand All @@ -148,7 +126,6 @@ def test_csharp(self):
parser = parse_code(code, clparser, cllexer)
tree = parser.compilation_unit()
st = get_tree_string(tree, parser)
fLOG(st.replace("\\n", "\n"))
assert len(st) > 0

def test_python3(self):
Expand All @@ -157,11 +134,6 @@ def test_python3(self):
from pyensae.languages.antlr_grammar_build import build_grammar
import pyensae.languages.antlr_grammar_use as source_parser

fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

# the grammar does not fully compile

code = """
Expand All @@ -181,7 +153,6 @@ def addition(x, y):
warnings.warn("Grammar for Python3 not ready yet: {0}".format(e))
return
st = get_tree_string(tree, parser)
fLOG(st.replace("\\n", "\n"))
assert len(st) > 0

def test_DOT(self):
Expand All @@ -190,11 +161,6 @@ def test_DOT(self):
from pyensae.languages.antlr_grammar_build import build_grammar
import pyensae.languages.antlr_grammar_use as source_parser

fLOG(
__file__,
self._testMethodName,
OutputPrint=__name__ == "__main__")

# the grammar does not fully compile

code = """
Expand All @@ -208,9 +174,9 @@ def test_DOT(self):
parser = parse_code(code, clparser, cllexer)
tree = parser.graph()
st = get_tree_string(tree, parser)
fLOG(st.replace("\\n", "\n"))
assert len(st) > 0


if __name__ == "__main__":
TestParseCode().test_csharp()
unittest.main()
2 changes: 1 addition & 1 deletion _unittests/ut_languages/test_parse_code_csharp.py
Expand Up @@ -56,7 +56,7 @@ def test_csharp_parse(self):
tree = parser.compilation_unit()
st = get_tree_string(tree, parser)
self.assertNotEmpty(st)
self.assertIn("/// <summary>", st)
self.assertIn("namespace", st)


if __name__ == "__main__":
Expand Down
6 changes: 5 additions & 1 deletion bin/update_grammars.bat
Expand Up @@ -19,6 +19,8 @@ set current=%~dp0
if %errorlevel% neq 0 exit /b %errorlevel%
%pythonexe% -u %current%..\setup.py update_grammars --g CSharpLexer.g4
if %errorlevel% neq 0 exit /b %errorlevel%
%pythonexe% -u %current%..\setup.py update_grammars --g CSharpPreprocessorParser.g4
if %errorlevel% neq 0 exit /b %errorlevel%
%pythonexe% -u %current%..\setup.py update_grammars --g CSharpParser.g4
if %errorlevel% neq 0 exit /b %errorlevel%
%pythonexe% -u %current%..\setup.py update_grammars --g DOT.g4
Expand All @@ -29,5 +31,7 @@ if %errorlevel% neq 0 exit /b %errorlevel%
if %errorlevel% neq 0 exit /b %errorlevel%
%pythonexe% -u %current%..\setup.py update_grammars --g SQLiteParser.g4
if %errorlevel% neq 0 exit /b %errorlevel%
%pythonexe% -u %current%..\setup.py update_grammars --g R.g4 RFilter.g4
%pythonexe% -u %current%..\setup.py update_grammars --g R.g4
if %errorlevel% neq 0 exit /b %errorlevel%
%pythonexe% -u %current%..\setup.py update_grammars --g RFilter.g4
if %errorlevel% neq 0 exit /b %errorlevel%
2 changes: 1 addition & 1 deletion build_script.bat
Expand Up @@ -5,7 +5,7 @@ set pythonexe="%1"
goto custom_python:

:default_value_python:
set pythonexe="c:\Python391_x64\python.exe"
set pythonexe="c:\Python3105_x64\python.exe"
if not exist %pythonexe% set pythonexe="c:\Python372_x64\python.exe"
:custom_python:
@echo [python] %pythonexe%
Expand Down
1 change: 1 addition & 0 deletions src/pyensae/_pylint_common.py
Expand Up @@ -31,6 +31,7 @@ def _private_test_style_src(fLOG, run_lint, verbose=False, pattern=".*[.]py$"):
"R0401: Cyclic import (src.pyensae.sql.sql_interface",
"R0401: Cyclic import (pyensae.sql.sql_interface",
"database_core2.py:230: R1714",
"RFilter.py",
])


Expand Down

0 comments on commit ef9f6a8

Please sign in to comment.