Changeset - 3fbd05d55303
[Not reviewed]
0 2 0
Brett Smith - 4 years ago 2020-05-30 02:05:26
brettcsmith@brettcsmith.org
cliutil: Add is_main_script function.
2 files changed with 9 insertions and 0 deletions:
0 comments (0 inline, 0 general)
conservancy_beancount/cliutil.py
Show inline comments
...
 
@@ -20,2 +20,3 @@ import argparse
 
import enum
 
import inspect
 
import logging
...
 
@@ -135,2 +136,7 @@ def add_version_argument(parser: argparse.ArgumentParser) -> argparse.Action:
 

	
 
def is_main_script() -> bool:
 
    """Return true if the caller is the "main" program."""
 
    stack = inspect.stack(context=False)
 
    return len(stack) <= 3 and stack[-1].function.startswith('<')
 

	
 
def setup_logger(logger: Union[str, logging.Logger]='',
tests/test_cliutil.py
Show inline comments
...
 
@@ -93,2 +93,5 @@ def test_excepthook_traceback(caplog):
 

	
 
def test_is_main_script():
 
    assert not cliutil.is_main_script()
 

	
 
@pytest.mark.parametrize('arg,expected', [
0 comments (0 inline, 0 general)