Skip to content

Commit

Permalink
Merge pull request #6 from dbosk/add-more-tests
Browse files Browse the repository at this point in the history
Add more tests
  • Loading branch information
dbosk authored Aug 6, 2023
2 parents 1296d80 + a227ba3 commit 5fc1c5b
Showing 1 changed file with 47 additions and 2 deletions.
49 changes: 47 additions & 2 deletions src/typerconf/init.nw
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,16 @@ def test_set_path_list():
assert gotten_value == value
@

We also want to test short paths.
<<test functions>>=
def test_set_short_path():
value = "Test Tester"
path = "contact"
conf.set(path, value)

assert conf.get(path) == value
@

When we want to remove a node, the pythonic way is to simply try to remove it.
If it doesn't exist, we silently fail.
The reasoning is as follows: the goal is to remove something; if it doesn't
Expand Down Expand Up @@ -329,6 +339,19 @@ def test_set_path_remove():
assert False
@

We also want to remove from a longer path.
<<test functions>>=
def test_set_path_list():
path = "courses.prgx22.TAs"
conf.set(path, None)
try:
conf.get(path)
except KeyError:
assert True
else:
assert False
@

We want to traverse the tree, we want to go to the immediate parent of the leaf
that we want to set a value for (or delete).
We iterate through the path.
Expand Down Expand Up @@ -948,6 +971,8 @@ if values == "":
values = None
@

\subsection{Testing the config command}

Let's test this command.
We'll set up the testing.
<<test functions>>=
Expand All @@ -963,7 +988,7 @@ Let's look at the actual tests.
<<run tests on [[cli]]>>=
# set example data
result = runner.invoke(cli,
["courses.datintro22.url", "--set", "https://..."])
["courses.datintro22.url", "--set", "https://..."])
assert result.exit_code == 0

# try access nonexisting
Expand All @@ -976,7 +1001,7 @@ assert "courses.datintro22.url = https://..." in result.stdout

# clear config
result = runner.invoke(cli,
["courses", "--set", None])
["courses", "--set", ""])
assert result.exit_code == 0

# check that it's cleared
Expand All @@ -999,6 +1024,26 @@ def test_cli_not_default_conf():
<<run tests on [[cli]]>>
@

We'll do another round of tests, but this time for shorter paths.
<<test functions>>=
def test_short_paths():
result = runner.invoke(cli, ["contact"])
assert result.exit_code != 0

result = runner.invoke(cli,
["contact", "--set", "me"])
assert result.exit_code == 0

result = runner.invoke(cli, ["contact"])
assert "contact = me" in result.stdout

result = runner.invoke(cli,
["contact", "--set", ""])
assert result.exit_code == 0

result = runner.invoke(cli, ["contact"])
assert result.exit_code != 0
@

\subsection{Autocompleting the path}

Expand Down

0 comments on commit 5fc1c5b

Please sign in to comment.