From 76c3d317490d73c2ad7937d1034d290a63969ca4 Mon Sep 17 00:00:00 2001 From: Jeff Forcier Date: Mon, 25 Jul 2016 17:22:39 -0700 Subject: [PATCH] Test proving and impl fixing re #56 When no link options are set, regular text is spat out instead. --- releases/__init__.py | 26 +++++++++++++++++++++----- tests/presentation.py | 18 ++++++++++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/releases/__init__.py b/releases/__init__.py index a93702f..e3f150d 100644 --- a/releases/__init__.py +++ b/releases/__init__.py @@ -73,19 +73,30 @@ def issues_role(name, rawtext, text, lineno, inliner, options={}, content=[]): # Lol @ access back to Sphinx config = inliner.document.settings.env.app.config if issue_no not in ('-', '0'): + ref = None if config.releases_issue_uri: # TODO: deal with % vs .format() ref = config.releases_issue_uri % issue_no elif config.releases_github_path: ref = "https://github.com/{0}/issues/{1}".format( config.releases_github_path, issue_no) - link = nodes.reference(rawtext, '#' + issue_no, refuri=ref, **options) + # Only generate a reference/link if we were able to make a URI + if ref: + identifier = nodes.reference( + rawtext, '#' + issue_no, refuri=ref, **options + ) + # Otherwise, just make it regular text + else: + identifier = nodes.raw( + rawtext=rawtext, text='#' + issue_no, format='html', + **options + ) else: - link = None + identifier = None issue_no = None # So it doesn't gum up dupe detection later # Additional 'new-style changelog' stuff if name in ISSUE_TYPES: - nodelist = issue_nodelist(name, link) + nodelist = issue_nodelist(name, identifier) spec = None keyword = None # TODO: sanity checks re: e.g. >2 parts, >1 instance of keywords, >1 @@ -112,7 +123,7 @@ def issues_role(name, rawtext, text, lineno, inliner, options={}, content=[]): return [node], [] # Return old style info for 'issue' for older changelog entries else: - return [link], [] + return [identifier], [] def release_nodes(text, slug, date, config): @@ -120,13 +131,18 @@ def release_nodes(text, slug, date, config): # title and give it these HTML attributes during render time) so...fuckit. # We were already doing fully raw elements elsewhere anyway. And who cares # about a PDF of a changelog? :x + uri = None if config.releases_release_uri: # TODO: % vs .format() uri = config.releases_release_uri % slug elif config.releases_github_path: uri = "https://github.com/{0}/tree/{1}".format( config.releases_github_path, slug) - link = '{1}'.format(uri, text) + # Only construct link tag if user actually configured release URIs somehow + if uri: + link = '{1}'.format(uri, text) + else: + link = text datespan = '' if date: datespan = ' {0}'.format(date) diff --git a/tests/presentation.py b/tests/presentation.py index d19485c..bef24c6 100644 --- a/tests/presentation.py +++ b/tests/presentation.py @@ -96,6 +96,24 @@ class presentation(Spec): } self._test_link(kwargs, 'release', 'explicit_release_1.0.2') + def completely_blank_uri_settings_does_not_asplode(self): + kwargs = { + 'release_uri': None, + 'issue_uri': None, + 'github_path': None, + } + # Get nodes for direct inspection + nodes = self._test_link(kwargs, 'release', None) + # Ensure release entry still displays release version. + # (These are curently constructed as raw text nodes so no other great + # way to test this. Meh.) + text = nodes[0][0][0].astext() + assert '>1.0.2 Bug] #15:' in text + + def _assert_prefix(self, entries, expectation): assert expectation in self._generate(*entries)[0][0][0]