Get started
Test the app
edge test finds every *_test.py file in the project and runs each one in a fresh interpreter. The tests use the test package. The project declares it like any other.
Declare the test package
Add the package and lock it again.
edge add testedge lockThe lock now holds both packages.
$ edge lock
+ json https://cdn.edgepython.com/pkg/json/0.1.0/app.edge
+ test https://cdn.edgepython.com/pkg/test/0.1.1/app.edge
wrote edge.locktext
Without it, the runner stops with declare test in edge.json (edge add test).
Write a test file
Create main_test.py beside main.py.
from test import test, raises
from .main import count_words, top_words
@test("counts words without case or punctuation")
def counts():
assert count_words("Hi, hi! Bye.") == {"hi": 2, "bye": 1}
@test("ranks by count, then alphabetically")
def ranks():
assert top_words("b a b c a b", 2) == [("b", 3), ("a", 2)]
@test("empty text has no words")
def empty():
assert top_words("") == []
@test("text must be a string")
def not_text():
with raises(AttributeError):
count_words(42)python
@test("description")registers the function below it as a test.- A plain
assertchecks a result. with raises(AttributeError)passes only when the block raises that exception.from .main importreadsmain.pybeside the test file. Its__main__block does not run.
The file never calls run(). The runner drives the test package after the file loads.
Run the tests
edge test$ edge test
pass. counts words without case or punctuation
pass. ranks by count, then alphabetically
pass. empty text has no words
pass. text must be a string
4 passed, 0 failed
(successful) main_test.py
1/1 files passed · 0.0stext
A failing assertion marks its test and the whole file.
$ edge test
pass. counts words without case or punctuation
fail. ranks by count, then alphabetically (AssertionError: )
pass. empty text has no words
pass. text must be a string
3 passed, 1 failed
(unsuccessful) main_test.py
0/1 files passed · 0.0stext
The command exits with 0 when every file passes and 1 when one fails. edge test covers the other exit codes. It also covers --web, the flag that runs the same files in a browser.