-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] Disable multiple help across files #35
Comments
You're calling What you can do is move that call to Note that this is a highly unusual way to structure code for Python. Normally you would call Your test logging code would go in a function of its own that you'd call after clize, e.g.:
You would do the same in In the future, you should look to avoid using This means making a way to have both the log-level setter and the "business" function be one function together. Fortunately you can pass functions as parameters in Python, e.g.
Or alternatively: Eventually you'll want to reverse the roles and make set_loglevel a decorator. But for now I think you can ignore this last section :) |
I'm sorry, is it correct structure? Code is working. Structure: D:.
│ body_check.py
│ config.py
│ run_tests.py
│ TextExample1.txt
│ TextExample2.txt
"""Configuration.
Configuration for tests.
Variables:
VERSION {str} -- version of module
all_txt_in_eric_room_wihtout_subfolders {list(current_directory)} -- get all files in current directory
"""
import glob
import logbook
import sys
VERSION = "0.1"
# Get all .txt file in a directory
# https://stackoverflow.com/a/3964689/5951529
all_txt_in_eric_room_wihtout_subfolders = glob.glob('*.txt')
def version():
"""Show version.
For details see:
https://clize.readthedocs.io/en/stable/dispatching.html#alternate-actions
"""
print(VERSION)
def v():
"""Alternative show version.
For details see: https://github.com/epsy/clize/issues/34
"""
print(VERSION)
def clize_log_level(*, logbook_level: 'll'="NOTICE"):
"""Change log levels via command line.
User select, which logging messages to see. See about 6 log levels here:
https://logbook.readthedocs.io/en/stable/quickstart.html
:param logbook_level: user select logging level
"""
if logbook_level == "DEBUG":
logbook.StreamHandler(sys.stdout,
level=logbook.DEBUG).push_application()
elif logbook_level == "NOTICE":
logbook.StreamHandler(sys.stdout,
level=logbook.NOTICE).push_application()
elif logbook_level == "ERROR":
logbook.StreamHandler(sys.stdout,
level=logbook.ERROR).push_application()
else:
logbook.StreamHandler(sys.stdout,
level=logbook.NOTICE).push_application()
"""Check files for body.
Check, contains files of current directory <body> or no.
"""
import logbook
from config import all_txt_in_eric_room_wihtout_subfolders
log = logbook.Logger("eric_body logbook")
body_test = True
def eric_body_function():
"""Check, contains body in a file, or no."""
for filename in all_txt_in_eric_room_wihtout_subfolders:
if "<body>" in open(filename).read():
log.debug(filename + " contains <body>")
else:
log.error(
"File " +
filename +
" not contain <body>.")
global body_test
body_test = False
def eric_body_summary():
"""Report, contains <body> in all files or no.
Use flags, see https://stackoverflow.com/a/48052480/5951529
"""
eric_body_function()
if body_test is True:
log.notice("All files contains <body>")
else:
log.error("Not all files contains <body>. Please, correct your files.")
"""Run tests.
Main file for running tests.
"""
import body_check
import logbook
from clize import run
from config import clize_log_level
from config import v
from config import version
log = logbook.Logger("run_tests logbook")
if __name__ == '__main__':
run(clize_log_level, alt=[version, v], exit=False)
body_check.eric_body_summary()
if body_check.body_test is True:
log.notice("Success!")
else:
log.error("Failure!")
Correct
<body>
Incorrect
<boty> Thanks. |
I'm sorry for additional question. This is similar to foot in the door. Thanks for the answer! |
Oh no. don't worry, I just had a busy week. It looks like this would work correctly, good job on restructuring things into functions. Is there still an issue? |
See #37 . Otherwise my code works. Thanks. |
1. Briefly
I don't understand, how I can disable multiple help, if my program contains multiple files.
2. Configuration
For example, I have a folder with 4 files:
config.py
(see [Question] Changing variable from command line #33):first_test.py
:second_test.py
:run_tests.py
:3. Behavior of the program
If I run
run_tests.py
, runfirst_test.py
andsecond_test.py
. Logging messages fromfirst_test.py
andsecond_test.py
return.The program works as expected:
4. Problem
One problem: help menu show for me 2 times:
If I have more
<number>_test
files, I have more help repeats.How I need edit in my code, that don't see help multiple times?
Thanks.
The text was updated successfully, but these errors were encountered: