MCPcopy
hub / github.com/hylang/hy / test_tracebacks

Function test_tracebacks

tests/test_bin.py:364–443  ·  view source on GitHub ↗

Make sure the printed tracebacks are correct.

()

Source from the content-addressed store, hash-verified

362
363
364def test_tracebacks():
365 """Make sure the printed tracebacks are correct."""
366
367 def req_err(x):
368 assert x == "hy.errors.HyRequireError: No module named 'not_a_real_module'"
369
370 # Modeled after
371 # > python -c 'import not_a_real_module'
372 # Traceback (most recent call last):
373 # File "<string>", line 1, in <module>
374 # ImportError: No module named not_a_real_module
375 _, error = run_cmd("hy", "(require not-a-real-module)", expect=1)
376 error_lines = error.splitlines()
377 if error_lines[-1] == "":
378 del error_lines[-1]
379 assert len(error_lines) <= 10
380 # Rough check for the internal traceback filtering
381 req_err(error_lines[-1])
382
383 _, error = run_cmd('hy -c "(require not-a-real-module)"', expect=1)
384 error_lines = error.splitlines()
385 assert len(error_lines) <= 4
386 req_err(error_lines[-1])
387
388 output, error = run_cmd('hy -i -c "(require not-a-real-module)"', '')
389 assert output.startswith("=> ")
390 req_err(error.splitlines()[2])
391
392 # Modeled after
393 # > python -c 'print("hi'
394 # File "<string>", line 1
395 # print("hi
396 # ^
397 # SyntaxError: EOL while scanning string literal
398 _, error = run_cmd(r'hy -c "(print \""', expect=1)
399 peoi_re = (
400 r"Traceback \(most recent call last\):\n"
401 r' File "(?:<string>|string-[0-9a-f]+)", line 1\n'
402 r' \(print "\n'
403 r" \^\n"
404 r"hy.PrematureEndOfInput"
405 )
406 assert re.search(peoi_re, error)
407
408 # Modeled after
409 # > python -i -c "print('"
410 # File "<string>", line 1
411 # print('
412 # ^
413 # SyntaxError: EOL while scanning string literal
414 # >>>
415 output, error = run_cmd(r'hy -c "(print \""', expect=1)
416 assert output == ''
417 assert re.match(peoi_re, error)
418
419 # Modeled after
420 # > python -c 'print(a)'
421 # Traceback (most recent call last):

Callers

nothing calls this directly

Calls 3

run_cmdFunction · 0.85
req_errFunction · 0.85
replaceMethod · 0.45

Tested by

no test coverage detected