Skip to content

Commit

Permalink
fixes for better docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyfast committed Sep 12, 2020
1 parent 04dea6e commit 77159b7
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
27 changes: 24 additions & 3 deletions pidgy/compat/markdown.ipynb
Expand Up @@ -65,8 +65,12 @@
" quote, length = self.QUOTES[self.QUOTES[0] in str], len(str)\n",
" left, right = length - len(str.lstrip()), len(str.rstrip())\n",
" if not str[left:right].strip(): return str\n",
" while str[right-1] == '\\\\':\n",
" right -= 1\n",
" if str[right-1] == '\\\\':\n",
" while str[right-1] == '\\\\':\n",
" right -= 1\n",
" else:\n",
" if str[left:right].endswith(quote[0]):\n",
" quote = {\"'''\": '\"\"\"', '\"\"\"': \"'''\"}[quote]\n",
" return str[:left] + quote + str[left:right] + quote + trailing + str[right:]\n",
"\n",
" def measure_base_indent(self, tokens, env):\n",
Expand Down Expand Up @@ -127,6 +131,15 @@
"## utility functions for parsing and rendering"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
" import doctest"
]
},
{
"cell_type": "code",
"execution_count": 4,
Expand Down Expand Up @@ -156,7 +169,15 @@
" for token in token.children:\n",
" code = filter_tangle_tokens(token, code)\n",
" else:\n",
" token.type in CODE_TYPES and token not in code and code.append(token)\n",
" if token.type in CODE_TYPES:\n",
" if token.type == \"code_block\":\n",
" while token.content.lstrip().startswith(\">>>\"):\n",
" start, end = next(doctest.DocTestParser._EXAMPLE_RE.finditer(token.content)).span()\n",
" token.map[0] = len(token.content[:end].splitlines())\n",
" token.content = token.content[end:]\n",
" if not token.content.strip(): return code\n",
" if token not in code:\n",
" code.append(token)\n",
" if code and (code[-1].type == \"fence\") and code[-1].info:\n",
" code.pop(-1)\n",
" return code or [\n",
Expand Down
2 changes: 1 addition & 1 deletion pidgy/tangle.ipynb
Expand Up @@ -308,4 +308,4 @@
},
"nbformat": 4,
"nbformat_minor": 4
}
}
12 changes: 7 additions & 5 deletions pidgy/testing.md
Expand Up @@ -16,6 +16,7 @@ we formally test code incrementally during interactive computing.
visitor = traitlets.Instance('ast.NodeTransformer')
results = traitlets.List()
trace = traitlets.Any()
update = traitlets.Bool(True)

@traitlets.default('trace')
def _default_trace(self):
Expand Down Expand Up @@ -49,8 +50,9 @@ we formally test code incrementally during interactive computing.
def stub(self):
return self.trace.stub()
def post_execute(self):
for test in self.results:
if self.trace.enabled:
with self.trace: test.test()
else: test.test()
test.update()
if self.update:
for test in self.results:
if self.trace.enabled:
with self.trace: test.test()
else: test.test()
test.update()

0 comments on commit 77159b7

Please sign in to comment.