fix: remove all warnings!
This commit is contained in:
parent
6d3759f3e4
commit
1af9610734
12 changed files with 135 additions and 25 deletions
|
|
@ -20,6 +20,7 @@ import os
|
|||
from warnings import filterwarnings
|
||||
from pathlib import Path
|
||||
from sys import exit
|
||||
from warnings import warn
|
||||
|
||||
from tiramisu_cmdline_parser import TiramisuCmdlineParser
|
||||
from tiramisu.error import PropertiesOptionError
|
||||
|
|
@ -59,15 +60,14 @@ def _main(arguments, do_not_print):
|
|||
return list(versions)
|
||||
for version in versions:
|
||||
print(version)
|
||||
else:
|
||||
manage_warnings(rougailconfig["cli.warnings"])
|
||||
config, err_warn = load_user_datas(rougailconfig)
|
||||
output = get_output(rougailconfig, config, err_warn)
|
||||
if do_not_print:
|
||||
return output.run()
|
||||
ret = output.print()
|
||||
if ret is False:
|
||||
exit(1)
|
||||
exit()
|
||||
config, err_warn = load_user_datas(rougailconfig)
|
||||
output = get_output(rougailconfig, config, err_warn)
|
||||
if do_not_print:
|
||||
return output.run()
|
||||
ret = output.print()
|
||||
if ret is False:
|
||||
exit(1)
|
||||
|
||||
|
||||
def load_cmd_user_datas(rougailconfig, arguments):
|
||||
|
|
@ -89,20 +89,27 @@ def load_cmd_user_datas(rougailconfig, arguments):
|
|||
env_prefix = ENV_PREFIX
|
||||
else:
|
||||
env_prefix = None
|
||||
user_data = rougailconfig_load(rougailconfig, config_file, env_prefix, True, display_warnings=cmd_config.option("cli.warnings").value.get(), raise_on_error=False, _arguments=arguments, _generate=False)
|
||||
# replays to display errors if needed
|
||||
user_data = rougailconfig_load(rougailconfig, config_file, env_prefix, True, _arguments=arguments, _generate=False)
|
||||
display_warnings = rougailconfig["cli.warnings"]
|
||||
manage_warnings(display_warnings)
|
||||
if not cmd_config.option("cli.versions").value.get():
|
||||
parser = TiramisuCmdlineParser(
|
||||
cmd_config,
|
||||
short_name_max_len=2,
|
||||
)
|
||||
parser.parse_args(arguments)
|
||||
if display_warnings and user_data["warnings"]:
|
||||
for warning in user_data["warnings"]:
|
||||
warn(warning)
|
||||
if manage_warnings:
|
||||
# replays to display errors if needed
|
||||
parser = TiramisuCmdlineParser(
|
||||
cmd_config,
|
||||
short_name_max_len=2,
|
||||
)
|
||||
parser.parse_args(arguments)
|
||||
if user_data["errors"]:
|
||||
raise Exception(user_data["errors"][0])
|
||||
|
||||
cmd_config.property.setdefault(origin_prop, "read_write", "append")
|
||||
cmd_config.property.remove("not_for_commandline")
|
||||
cmd_config.property.read_only()
|
||||
cmd_config.property.remove("not_for_commandline")
|
||||
|
||||
return cmd_config
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ GNU General Public License for more details.
|
|||
You should have received a copy of the GNU General Public License
|
||||
along with Mtools. If not, see <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
from warnings import warn
|
||||
from rougail.user_datas import UserDatas
|
||||
|
||||
|
||||
|
|
@ -23,8 +22,6 @@ def load(rougailconfig: "RougailConfig",
|
|||
yaml_file: str=None,
|
||||
env_prefix: str=None,
|
||||
commandline: bool=False,
|
||||
display_warnings: bool=True,
|
||||
raise_on_error: bool=True,
|
||||
_arguments=None,
|
||||
_generate=True
|
||||
):
|
||||
|
|
@ -41,11 +38,6 @@ def load(rougailconfig: "RougailConfig",
|
|||
if commandline:
|
||||
user_datas.extend(from_cmdline(cmd_config, _arguments))
|
||||
user_data = UserDatas(cmd_config).user_datas(user_datas)
|
||||
if display_warnings and user_data["warnings"]:
|
||||
for warning in user_data["warnings"]:
|
||||
warn(warning)
|
||||
if raise_on_error and user_data["errors"]:
|
||||
raise Exception(user_data["errors"][0])
|
||||
cmd_config.property.importation(origin_prop)
|
||||
return user_data
|
||||
|
||||
|
|
|
|||
8
tests/rougailcli_file/structures_warnings/file.yml
Normal file
8
tests/rougailcli_file/structures_warnings/file.yml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
version: 1.1
|
||||
|
||||
my_variable:
|
||||
redefine: true
|
||||
validators: # validators in jinja without description makes warnings
|
||||
- jinja: |-
|
||||
{{ _.my_variable != "my_value" }}
|
||||
1
tests/rougailcli_file/warnings.txt
Normal file
1
tests/rougailcli_file/warnings.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
["family \"configuration rougail-json\" is disabled, \"test mandatories variables before display in json\" will be ignored when loading from the YAML file \"warnings.yml\""]
|
||||
7
tests/rougailcli_file/warnings.yml
Normal file
7
tests/rougailcli_file/warnings.yml
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
main_structural_directories:
|
||||
- structures
|
||||
doc:
|
||||
output_format: console
|
||||
json:
|
||||
mandatory: true
|
||||
1
tests/rougailcli_file/warnings2.txt
Normal file
1
tests/rougailcli_file/warnings2.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
[]
|
||||
9
tests/rougailcli_file/warnings2.yml
Normal file
9
tests/rougailcli_file/warnings2.yml
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
main_structural_directories:
|
||||
- structures
|
||||
doc:
|
||||
output_format: console
|
||||
json:
|
||||
mandatory: true
|
||||
cli:
|
||||
warnings: false
|
||||
1
tests/rougailcli_file/warnings3.txt
Normal file
1
tests/rougailcli_file/warnings3.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
["family \"configuration rougail-json\" is disabled, \"test mandatories variables before display in json\" will be ignored when loading from the YAML file \"warnings3.yml\"", "\"validators\" is a calculation for my_variable but has no description in \"structures/file.yml\" and \"structures_warnings/file.yml\""]
|
||||
8
tests/rougailcli_file/warnings3.yml
Normal file
8
tests/rougailcli_file/warnings3.yml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
main_structural_directories:
|
||||
- structures
|
||||
- structures_warnings
|
||||
doc:
|
||||
output_format: console
|
||||
json:
|
||||
mandatory: true
|
||||
1
tests/rougailcli_file/warnings4.txt
Normal file
1
tests/rougailcli_file/warnings4.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
[]
|
||||
10
tests/rougailcli_file/warnings4.yml
Normal file
10
tests/rougailcli_file/warnings4.yml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
---
|
||||
main_structural_directories:
|
||||
- structures
|
||||
- structures_warnings
|
||||
doc:
|
||||
output_format: console
|
||||
json:
|
||||
mandatory: true
|
||||
cli:
|
||||
warnings: false
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
import warnings
|
||||
from pathlib import Path
|
||||
from contextlib import chdir
|
||||
from json import dumps, loads
|
||||
|
|
@ -119,3 +120,67 @@ def test_cli_rougailcli_mix():
|
|||
with filename.open() as fh:
|
||||
data = loads(fh.read())
|
||||
assert ret == (True, data)
|
||||
|
||||
|
||||
def test_cli_rougailcli_warning():
|
||||
with chdir(test_dir / 'rougailcli_file'):
|
||||
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'warnings.yml'
|
||||
with warnings.catch_warnings(record=True) as rougail_wn:
|
||||
warnings.simplefilter("always", UserWarning)
|
||||
main(["-o", "doc", "--doc.output_format", "asciidoc"], do_not_print=True)
|
||||
ret = [str(w.message) for w in rougail_wn]
|
||||
filename = Path('warnings.txt')
|
||||
if not filename.is_file():
|
||||
with filename.open('w') as fh:
|
||||
fh.write(dumps([str(w.message) for w in rougail_wn]))
|
||||
with filename.open() as fh:
|
||||
data = loads(fh.read())
|
||||
assert ret == data, str(filename.absolute())
|
||||
|
||||
|
||||
def test_cli_rougailcli_not_warning():
|
||||
with chdir(test_dir / 'rougailcli_file'):
|
||||
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'warnings2.yml'
|
||||
with warnings.catch_warnings(record=True) as rougail_wn:
|
||||
warnings.simplefilter("always", UserWarning)
|
||||
main(["-o", "doc", "--doc.output_format", "asciidoc"], do_not_print=True)
|
||||
filename = Path('warnings2.txt')
|
||||
ret = [str(w.message) for w in rougail_wn]
|
||||
if not filename.is_file():
|
||||
with filename.open('w') as fh:
|
||||
fh.write(dumps(ret))
|
||||
with filename.open() as fh:
|
||||
data = loads(fh.read())
|
||||
assert ret == data, str(filename.absolute())
|
||||
|
||||
|
||||
def test_cli_rougailcli_warning2():
|
||||
with chdir(test_dir / 'rougailcli_file'):
|
||||
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'warnings3.yml'
|
||||
with warnings.catch_warnings(record=True) as rougail_wn:
|
||||
warnings.simplefilter("always", UserWarning)
|
||||
main(["-o", "doc", "--doc.output_format", "asciidoc"], do_not_print=True)
|
||||
ret = [str(w.message) for w in rougail_wn]
|
||||
filename = Path('warnings3.txt')
|
||||
if not filename.is_file():
|
||||
with filename.open('w') as fh:
|
||||
fh.write(dumps([str(w.message) for w in rougail_wn]))
|
||||
with filename.open() as fh:
|
||||
data = loads(fh.read())
|
||||
assert ret == data, str(filename.absolute())
|
||||
|
||||
|
||||
def test_cli_rougailcli_not_warning2():
|
||||
with chdir(test_dir / 'rougailcli_file'):
|
||||
os.environ["ROUGAILCLI_CLI.CONFIG_FILE"] = 'warnings4.yml'
|
||||
with warnings.catch_warnings(record=True) as rougail_wn:
|
||||
warnings.simplefilter("always", UserWarning)
|
||||
main(["-o", "doc", "--doc.output_format", "asciidoc"], do_not_print=True)
|
||||
filename = Path('warnings4.txt')
|
||||
ret = [str(w.message) for w in rougail_wn]
|
||||
if not filename.is_file():
|
||||
with filename.open('w') as fh:
|
||||
fh.write(dumps(ret))
|
||||
with filename.open() as fh:
|
||||
data = loads(fh.read())
|
||||
assert ret == data, str(filename.absolute())
|
||||
|
|
|
|||
Loading…
Reference in a new issue