Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_parse_eval_single_want():
string = ub.codeblock(
'''
>>> a = 1
>>> 1 / 0
We have a want
''')
self = doctest_parser.DoctestParser()
parts = self.parse(string)
raw_source_lines = string.split('\n')[:-1]
ps1_linenos, eval_final = self._locate_ps1_linenos(raw_source_lines)
assert ps1_linenos == [0, 1]
assert eval_final
# Only one part because there is no want
assert len(parts) == 2
print('')
print('!!! FAILED !!!')
print('failpoint = {!r}'.format(failpoint))
import ubelt as ub
import traceback
tb_text = traceback.format_exc()
tb_text = ub.highlight_code(tb_text)
tb_text = ub.indent(tb_text)
print(tb_text)
print('Failed to parse string = <<<<<<<<<<<')
print(string)
print('>>>>>>>>>>> # end string')
print('info = {}'.format(ub.repr2(info)))
print('-----')
print('orig_ex = {}'.format(orig_ex))
print('labeled_lines = {}'.format(ub.repr2(labeled_lines)))
print('grouped_lines = {}'.format(ub.repr2(grouped_lines, nl=3)))
print('all_parts = {}'.format(ub.repr2(all_parts)))
print('')
sys.exit(1)
raise exceptions.DoctestParseError(
'Failed to parse doctest in {}'.format(failpoint),
string=string, info=info, orig_ex=orig_ex)
if DEBUG > 1:
print('\n===== FINISHED PARSE ====')
return all_parts
import ubelt as ub
import traceback
tb_text = traceback.format_exc()
tb_text = ub.highlight_code(tb_text)
tb_text = ub.indent(tb_text)
print(tb_text)
print('Failed to parse string = <{[<{[<{[')
print(string)
print(']}>a]}>]}> # end string')
print('info = {a}'.format(a=ub.repr2(info)))
print('-----')
print('orig_ex = {a}'.format(a=orig_ex))
print('labeled_lines = {a}'.format(a=ub.repr2(labeled_lines)))
print('grouped_lines = {a}'.format(a=ub.repr2(grouped_lines, nl=3)))
print('all_parts = {a}'.format(a=ub.repr2(all_parts)))
print('')
# sys.exit(1)
raise exceptions.DoctestParseError(
'Failed to parse doctest in {a}'.format(a=failpoint),
string=string, info=info, orig_ex=orig_ex)
if DEBUG > 1:
print('\n===== FINISHED PARSE ====')
return all_parts
"""
CommandLine:
pytest ubelt/tests/test_cmd.py::test_cmd_tee_thread -s
python ubelt/tests/test_cmd.py test_cmd_tee_thread
"""
if 'tqdm' in sys.modules:
if tuple(map(int, sys.modules['tqdm'].__version__.split('.'))) < (4, 19):
pytest.skip(reason='threads cause issues with early tqdms')
import threading
# check which threads currently exist (ideally 1)
existing_threads = list(threading.enumerate())
print('existing_threads = {!r}'.format(existing_threads))
command = 'python -c "for i in range(10): print(str(i))"'
result = ub.cmd(command, verbose=0, tee_backend='thread')
assert result['out'] == '\n'.join(list(map(str, range(10)))) + '\n'
after_threads = list(threading.enumerate())
print('after_threads = {!r}'.format(after_threads))
assert len(existing_threads) <= len(after_threads), (
'we should be cleaning up our threads')
def test_static_import_without_init():
"""
python ~/code/mkinit/tests/test_with_dummy.py test_static_import_without_init
"""
import mkinit
cache_dpath = ub.ensure_app_cache_dir('mkinit/tests')
paths = make_dummy_package(cache_dpath)
ub.delete(paths['root_init'])
modpath = paths['root']
text = mkinit.static_init(modpath)
check_dummy_root_init(text)
def test_static_import_without_init():
"""
python ~/code/mkinit/tests/test_with_dummy.py test_static_import_without_init
"""
import mkinit
cache_dpath = ub.ensure_app_cache_dir('mkinit/tests')
paths = make_dummy_package(cache_dpath)
ub.delete(paths['root_init'])
modpath = paths['root']
text = mkinit.static_init(modpath)
check_dummy_root_init(text)
def test_dynamic_init():
"""
python ~/code/mkinit/tests/test_with_dummy.py test_dynamic_init
"""
import mkinit
cache_dpath = ub.ensure_app_cache_dir('mkinit/tests')
paths = make_dummy_package(cache_dpath, 'dynamic_dummy_mod1')
module = ub.import_module_from_path(paths['root'])
text = mkinit.dynamic_mkinit.dynamic_init(module.__name__)
print(text)
for i in range(1, 15):
want = 'good_attr_{:02d}'.format(i)
assert want in text, 'missing {}'.format(want)
def test_static_init():
"""
python ~/code/mkinit/tests/test_with_dummy.py test_static_import_without_init
"""
import mkinit
cache_dpath = ub.ensure_app_cache_dir('mkinit/tests')
paths = make_dummy_package(cache_dpath)
modpath = paths['root']
text = mkinit.static_init(modpath)
check_dummy_root_init(text)
if labeled_lines is None:
failpoint = '_label_docsrc_lines'
elif grouped_lines is None:
failpoint = '_group_labeled_lines'
elif all_parts is None:
failpoint = '_package_groups'
if DEBUG:
print('')
print('!!! FAILED !!!')
print('failpoint = {!r}'.format(failpoint))
import ubelt as ub
import traceback
tb_text = traceback.format_exc()
tb_text = ub.highlight_code(tb_text)
tb_text = ub.indent(tb_text)
print(tb_text)
print('Failed to parse string = <<<<<<<<<<<')
print(string)
print('>>>>>>>>>>> # end string')
print('info = {}'.format(ub.repr2(info)))
print('-----')
print('orig_ex = {}'.format(orig_ex))
print('labeled_lines = {}'.format(ub.repr2(labeled_lines)))
print('grouped_lines = {}'.format(ub.repr2(grouped_lines, nl=3)))
print('all_parts = {}'.format(ub.repr2(all_parts)))
print('')
sys.exit(1)
raise exceptions.DoctestParseError(
def test_cache_hit():
cacher = ub.Cacher('name', 'params', verbose=2)
cacher.clear()
assert not cacher.exists()
cacher.save(['some', 'data'])
assert cacher.exists()
data = cacher.load()
assert data == ['some', 'data']