Skip to content

Commit

Permalink
ignore links for ipynb files (#39)
Browse files Browse the repository at this point in the history
* ignore links for ipynb files

* update test workflow macos version

* update ipynb test case

* update example file for test case

* fix other test cases
  • Loading branch information
pratyakshajha authored Oct 18, 2021
1 parent 57aa513 commit 4563ee7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
fail-fast: false
matrix:
PLATFORM: ['ubuntu-latest', 'macos-latest', 'windows-latest']
PLATFORM: ['ubuntu-latest', 'macos-10.15', 'windows-latest']
PYTHON_VERSION: ['3.6', '3.9']
steps:
- name: Checkout
Expand Down
9 changes: 8 additions & 1 deletion examples/linkcheck.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,15 @@
"\n",
"[markdown local bad](doesntexist.html)\n",
"\n",
"[markdown absolute](/tmp)"
"[markdown absolute](/tmp)\n",
"\n",
"[markdown link to ignore](http://example.com/404)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
Expand Down
7 changes: 6 additions & 1 deletion pytest_check_links/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,12 @@ def _items_from_notebook(self):
html = MarkdownWithMath(renderer=renderer).render(cell.source)
basename = 'Cell %i' % cell_num
for item in links_in_html(basename, self, html):
yield item
ignore = False
for pattern in self.ignore_links:
if re.match(pattern, item.target):
ignore = True
if not ignore:
yield item

def collect(self):
path = self.fspath
Expand Down
2 changes: 1 addition & 1 deletion test/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_cache_expiry(testdir, base_args, cache_name, tmpdir):
args = base_args + ["--check-links-cache-expire-after", "2"]
if cache_name:
args += ["--check-links-cache-name", os.path.join(str(tmpdir), cache_name)]
expected = dict(passed=3, failed=3)
expected = dict(passed=3, failed=4)
t0 = time.time()
result = testdir.runpytest(*args)
t1 = time.time()
Expand Down
4 changes: 3 additions & 1 deletion test/test_check_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
def test_ipynb(testdir):
testdir.copy_example('linkcheck.ipynb')
result = testdir.runpytest("-v", "--check-links")
result.assert_outcomes(passed=3, failed=4)
result = testdir.runpytest("-v", "--check-links", "--check-links-ignore", "http.*example.com/.*")
result.assert_outcomes(passed=3, failed=3)

def test_markdown(testdir):
Expand Down Expand Up @@ -47,4 +49,4 @@ def test_link_ext(testdir):
testdir.copy_example('rst.rst')
testdir.copy_example('markdown.md')
result = testdir.runpytest("-v", "--check-links", "--links-ext=md,ipynb")
result.assert_outcomes(passed=11, failed=7)
result.assert_outcomes(passed=11, failed=8)

0 comments on commit 4563ee7

Please sign in to comment.