Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion tanco/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@
"""
command-line driver for tanco client.
"""
import argparse
import asyncio
import cmd as cmdlib
import os
import shlex
import sqlite3
import subprocess
import sys
import webbrowser
import pprint

import jwt as jwtlib
import websockets as w

from . import database as db
from . import model as m
from . import orgtest, runner
from .client import TancoClient
from .model import Config, TestDescription

Check failure on line 23 in tanco/driver.py

View workflow job for this annotation

GitHub Actions / test

Ruff (I001)

tanco/driver.py:5:1: I001 Import block is un-sorted or un-formatted

class TancoDriver(cmdlib.Cmd):
prompt = 'tanco> '
Expand Down Expand Up @@ -154,18 +154,18 @@
num_desc_removed = sum(1 for line in lines if line.strip().startswith(': '))

# Show summary
has_todo = any(l.strip().lower().startswith('#+todo:') for l in lines)

Check failure on line 157 in tanco/driver.py

View workflow job for this annotation

GitHub Actions / test

Ruff (E741)

tanco/driver.py:157:68: E741 Ambiguous variable name: `l`
print(f'{"Would migrate" if args.check else "Migrating"}: {args.file}')
print(f'Changes:')

Check failure on line 159 in tanco/driver.py

View workflow job for this annotation

GitHub Actions / test

Ruff (F541)

tanco/driver.py:159:15: F541 f-string without any placeholders
print(f' - Add #+tanco-format: 0.2 directive')

Check failure on line 160 in tanco/driver.py

View workflow job for this annotation

GitHub Actions / test

Ruff (F541)

tanco/driver.py:160:15: F541 f-string without any placeholders
if not has_todo:
print(f' - Add #+todo: TODO | DONE TEST directive')

Check failure on line 162 in tanco/driver.py

View workflow job for this annotation

GitHub Actions / test

Ruff (F541)

tanco/driver.py:162:19: F541 f-string without any placeholders
print(f' - Migrate {num_tests} tests')
print(f' - Remove {num_name_removed} #+name: directives')
print(f' - Remove TODO/DONE from test headlines')

Check failure on line 165 in tanco/driver.py

View workflow job for this annotation

GitHub Actions / test

Ruff (F541)

tanco/driver.py:165:15: F541 f-string without any placeholders
print(f' - Remove {num_title_removed} = title lines')
print(f' - Remove {num_desc_removed} : description lines')
print(f' - Move description text to test bodies')

Check failure on line 168 in tanco/driver.py

View workflow job for this annotation

GitHub Actions / test

Ruff (F541)

tanco/driver.py:168:15: F541 f-string without any placeholders
print()

if args.check:
Expand Down Expand Up @@ -229,7 +229,7 @@
try:
arg = self.result[int(arg)]['name']
except IndexError:
print(f"Sorry, challenge number {arg} not found.")

Check failure on line 232 in tanco/driver.py

View workflow job for this annotation

GitHub Actions / test

Ruff (Q000)

tanco/driver.py:232:23: Q000 Double quotes found but single quotes preferred
return
if arg == '--local':
print('starting local challenge.')
Expand Down Expand Up @@ -465,6 +465,19 @@
except runner.NoTestPlanError:
runner.error(cfg, ['No challenge selected.',
'Use `tanco init`, `tanco test -t file.org`, or set TEST_PLAN environment variable.'])
except runner.NoTestsFoundError as e:
runner.error(cfg, [str(e),
'',
'For org files, tests should be defined using:',
' ** TEST testname : title',
' #+begin_src',
' > input line',
' expected output',
' #+end_src'])
except FileNotFoundError as e:
runner.error(cfg, [f'Test file not found: {e.filename}',
'',
'Make sure the path is correct and the file exists.'])
except runner.StopTesting:
pass
except Exception:
Expand Down Expand Up @@ -531,8 +544,21 @@
runner.run_tests(cfg)
except runner.NoTestPlanError:
print("No tests specified. Use --tests PATH or ensure you're in a tanco project.")
except runner.NoTestsFoundError as e:
print(str(e))
print()
print('For org files, tests should be defined using:')
print(' ** TEST testname : title')
print(' #+begin_src')
print(' > input line')
print(' expected output')
print(' #+end_src')
except FileNotFoundError as e:
print(f'Test file not found: {e.filename}')
print()
print('Make sure the path is correct and the file exists.')
except runner.StopTesting:
pass # Normal exit after test failure
pass # Normal exit after test failure
except Exception:
# handle_unexpected_error already prints traceback
runner.handle_unexpected_error(cfg)
Expand Down
27 changes: 26 additions & 1 deletion tanco/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ class NoTestPlanError(Exception):
pass


class NoTestsFoundError(Exception):
"""Raised when a test source exists but contains no tests."""


class StopTesting(Exception):
pass

Expand Down Expand Up @@ -354,6 +358,14 @@ def run_tests(cfg: Config, names=None):
challenge = get_challenge(cfg)
tests = challenge.tests

# Check for empty tests list
if not tests:
source = cfg.test_path or cfg.test_plan or 'database'
raise NoTestsFoundError(
f'No tests found in {source}. '
'Make sure the file contains valid test definitions.',
)

# Use persistent process mode if restart_cmd is configured
if cfg.restart_cmd and cfg.restart_expect:
run_tests_persistent(cfg, tests, names)
Expand Down Expand Up @@ -502,8 +514,21 @@ def main(names: list[str]):
try:
run_tests(cfg, names)
except NoTestPlanError:
error(cfg, ['No challenge selected.'
error(cfg, ['No challenge selected.',
'Use `tanco init` or set TEST_PLAN environment variable.'])
except NoTestsFoundError as e:
error(cfg, [str(e),
'',
'For org files, tests should be defined using:',
' ** TEST testname : title',
' #+begin_src',
' > input line',
' expected output',
' #+end_src'])
except FileNotFoundError as e:
error(cfg, [f'Test file not found: {e.filename}',
'',
'Make sure the path is correct and the file exists.'])
except StopTesting:
pass
except Exception:
Expand Down
Loading