Lint, improve coverage, rm unused code

This commit is contained in:
Peter Eckersley
2016-08-08 15:45:49 -07:00
parent da7e429125
commit f0c2ed3059
2 changed files with 18 additions and 15 deletions
+1 -15
View File
@@ -540,7 +540,7 @@ def _comment_directive(block, location):
if isinstance(next_entry, list):
if "Certbot" in next_entry[-1]:
return
next_entry = next_entry.spaced[0]
next_entry = next_entry.spaced[0] # pylint: disable=no-member
block.insert(location + 1, COMMENT[:])
if "\n" not in next_entry:
block.insert(location + 2, '\n')
@@ -584,17 +584,3 @@ def _add_directive(block, directive, replace):
'tried to insert directive "{0}" but found '
'conflicting "{1}".'.format(directive, block[location]))
def _comment_spaced_block(block):
"""Adds a "managed by Certbot" comment to every directive."""
comment = " # managed by Certbot"
indent = 80 - len(comment)
for i, entry in enumerate(block):
if isinstance(entry, list):
line = "".join(entry)
line = "".join(c for c in line if c != "\n")
linelength = len(line)
extra = indent - linelength
if extra < 0:
extra = 0
block[i][-1] += extra * " " + comment
@@ -219,6 +219,23 @@ class NginxParserTest(util.NginxTest):
self.assertEqual(winner,
parser.get_best_match(target_name, names[i]))
def test_comment_directive(self):
# pylint: disable=protected-access
block = nginxparser.UnspacedList([
["\n", "a", " ", "b", "\n"],
["c", " ", "d"],
["\n", "e", " ", "f"]])
from certbot_nginx.parser import _comment_directive, COMMENT
_comment_directive(block, 1)
_comment_directive(block, 0)
self.assertEqual(block.spaced, [
["\n", "a", " ", "b", "\n"],
COMMENT,
"\n",
["c", " ", "d"],
COMMENT,
["\n", "e", " ", "f"]])
def test_get_all_certs_keys(self):
nparser = parser.NginxParser(self.config_path, self.ssl_options)
filep = nparser.abs_path('sites-enabled/example.com')