aboutsummaryrefslogtreecommitdiffstats
path: root/nbs/test.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'nbs/test.ipynb')
-rw-r--r--nbs/test.ipynb80
1 files changed, 78 insertions, 2 deletions
diff --git a/nbs/test.ipynb b/nbs/test.ipynb
index 3d32563..5645626 100644
--- a/nbs/test.ipynb
+++ b/nbs/test.ipynb
@@ -703,8 +703,8 @@
" if negstr is None: negstr = f'not {cmp.__name__}'\n",
" args_src, _ = get_call_args(frames_up)\n",
" lines = [f\"{repr(a)} {negstr} {repr(b)}\"]\n",
- " if repr(a) != args_src[0]: lines.append(f\" where {repr(a)} = {args_src[0]}\")\n",
- " if repr(b) != args_src[1]: lines.append(f\" where {repr(b)} = {args_src[1]}\")\n",
+ " if len(args_src) > 0 and repr(a) != args_src[0]: lines.append(f\" where {repr(a)} = {args_src[0]}\")\n",
+ " if len(args_src) > 1 and repr(b) != args_src[1]: lines.append(f\" where {repr(b)} = {args_src[1]}\")\n",
" assert cmp(a, b), \"\\n\".join(lines)\n"
]
},
@@ -968,6 +968,82 @@
]
},
{
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "9523b71e",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#| export\n",
+ "def is_true(a):\n",
+ " \"Assert that a is truthy.\"\n",
+ " expect(bool(a), True, operator.eq, negstr='is not truthy', frames_up=2)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "505710d7",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "is_true(True)\n",
+ "is_true(\"abc\")\n",
+ "is_true(123)\n",
+ "is_true(['a'])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "183b172b",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "with raises(): is_true(False)\n",
+ "with raises(): is_true(\"\")\n",
+ "with raises(): is_true([])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "f76c0add",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "#| export\n",
+ "def is_false(a):\n",
+ " \"Assert that a is falsy.\"\n",
+ " expect(bool(a), False, operator.eq, negstr='is not falsy', frames_up=2)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "cc6907f0",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "is_false(False)\n",
+ "is_false(\"\")\n",
+ "is_false([])"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "6c583e54",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "with raises(): is_false(True)\n",
+ "with raises(): is_false(\"abc\")\n",
+ "with raises(): is_false(123)\n",
+ "with raises(): is_false(['a'])"
+ ]
+ },
+ {
"cell_type": "markdown",
"id": "33be6990",
"metadata": {},