Skip to content

Commit

Permalink
v2.1.3
Browse files Browse the repository at this point in the history
--------
2023-07-21:
    - require minimum python 3.8
    - remove python 3.7 tests
    - introduce PEP517 packaging standard
    - introduce pyproject.toml build-system
    - remove mypy.ini
    - remove pytest.ini
    - remove setup.cfg
    - remove setup.py
    - remove .bettercodehub.yml
    - remove .travis.yml
    - update black config
    - clean ./tests/test_cli.py
    - add codeql badge
    - move 3rd_party_stubs outside the src directory to ``./.3rd_party_stubs``
    - add pypy 3.10 tests
    - add python 3.12-dev tests
  • Loading branch information
bitranox committed Jul 21, 2023
1 parent 51bf331 commit c4dc5e4
Showing 1 changed file with 18 additions and 17 deletions.
35 changes: 18 additions & 17 deletions rst_include/libs/lib_block_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@
def get_option_value_from_block_or_raise_if_empty_or_invalid(option: str, block: Block, value_must_be_int: bool = False) -> str:

"""
>>> block = lib_test.get_test_block_ok()
>>> my_block = lib_test.get_test_block_ok()
>>> # test ok
>>> get_option_value_from_block_or_raise_if_empty_or_invalid('code', block)
>>> get_option_value_from_block_or_raise_if_empty_or_invalid('code', my_block)
'python'
>>> # empty value
>>> get_option_value_from_block_or_raise_if_empty_or_invalid('pass-through1', block)
>>> get_option_value_from_block_or_raise_if_empty_or_invalid('pass-through1', my_block)
Traceback (most recent call last):
...
ValueError: Error in File ".../README.template.rst", Line 47107: option "pass-through1" has no value
>>> # option not found
>>> get_option_value_from_block_or_raise_if_empty_or_invalid('no-option', block)
>>> get_option_value_from_block_or_raise_if_empty_or_invalid('no-option', my_block)
Traceback (most recent call last):
...
ValueError: Error in File: ".../README.template.rst", option "no-option" not found in block starting with Line: 47100
>>> # option check type integer ok
>>> get_option_value_from_block_or_raise_if_empty_or_invalid('start-line', block, value_must_be_int=True)
>>> get_option_value_from_block_or_raise_if_empty_or_invalid('start-line', my_block, value_must_be_int=True)
'10'
>>> # option check type not integer
>>> get_option_value_from_block_or_raise_if_empty_or_invalid('start-after', block, value_must_be_int=True)
>>> get_option_value_from_block_or_raise_if_empty_or_invalid('start-after', my_block, value_must_be_int=True)
Traceback (most recent call last):
...
TypeError: Error in File ".../README.template.rst", Line 47105: option "start-after" has to be integer
Expand All @@ -56,8 +56,8 @@ def get_option_value_from_block_or_raise_if_empty_or_invalid(option: str, block:

def get_option_value_from_block(option: str, block: Block) -> str:
"""
>>> block = lib_test.get_test_block_ok()
>>> get_option_value_from_block('code', block)
>>> my_block = lib_test.get_test_block_ok()
>>> get_option_value_from_block('code', my_block)
'python'
>>> get_option_value_from_block('encoding', block)
'utf-8'
Expand All @@ -83,8 +83,8 @@ def get_option_value_from_source_line(source_line: SourceLine) -> str:

def is_option_in_block(option: str, block: Block) -> bool:
"""
>>> block = lib_test.get_test_block_ok()
>>> is_option_in_block('code', block)
>>> my_block = lib_test.get_test_block_ok()
>>> is_option_in_block('code', my_block)
True
>>> is_option_in_block('no-option', block)
False
Expand All @@ -100,8 +100,8 @@ def is_option_in_block(option: str, block: Block) -> bool:

def get_source_line_number_for_option(option: str, block: Block) -> int:
"""
>>> block = lib_test.get_test_block_ok()
>>> get_source_line_number_for_option('code', block)
>>> my_block = lib_test.get_test_block_ok()
>>> get_source_line_number_for_option('code', my_block)
47101
>>> get_source_line_number_for_option('encoding', block)
47102
Expand All @@ -121,8 +121,8 @@ def get_source_line_number_for_option(option: str, block: Block) -> int:

def is_option_in_source_line(source_line: SourceLine, option: str) -> bool:
"""
>>> source_line = lib_classes.SourceLine(line_number=4711, content=' :code:')
>>> is_option_in_source_line(source_line, 'code')
>>> my_source_line = lib_classes.SourceLine(line_number=4711, content=' :code:')
>>> is_option_in_source_line(my_source_line, 'code')
True
>>> is_option_in_source_line(source_line, 'encoding')
False
Expand All @@ -137,8 +137,8 @@ def is_option_in_source_line(source_line: SourceLine, option: str) -> bool:

def get_option_key_from_source_line(source_line: SourceLine) -> str:
"""
>>> source_line = lib_classes.SourceLine(line_number=4711, content=' :code:')
>>> get_option_key_from_source_line(source_line)
>>> my_source_line = lib_classes.SourceLine(line_number=4711, content=' :code:')
>>> get_option_key_from_source_line(my_source_line)
'code'
"""
key = source_line.content.split(':')[1]
Expand All @@ -147,7 +147,8 @@ def get_option_key_from_source_line(source_line: SourceLine) -> str:

def log_and_raise_value_error_if_option_not_in_block(option: str, block: Block) -> None:
if not is_option_in_block(option, block):
s_error = f'Error in File: "{block.source}", option "{option}" not found in block starting with Line: {block.l_source_lines[0].line_number}' # noqa: E713 # for python 3.12beta
s_error = f'Error in File: "{block.source}", option "{option}' \
f'" not found in block starting with Line: {block.l_source_lines[0].line_number}' # noqa: E713 # for python 3.12beta
lib_log_utils.log_error(s_error)
raise ValueError(s_error)

Expand Down

0 comments on commit c4dc5e4

Please sign in to comment.