Skip to content
This repository has been archived by the owner on Jun 25, 2020. It is now read-only.

Commit

Permalink
Support multi-file directory globbing
Browse files Browse the repository at this point in the history
  • Loading branch information
di committed Jan 13, 2016
1 parent 8844f15 commit fc9781e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
18 changes: 15 additions & 3 deletions scripts/html_lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
from __future__ import unicode_literals

import codecs
import glob
import io
import os
import sys

import docopt
Expand Down Expand Up @@ -106,11 +108,21 @@ def main():
return 1

exclude = [_DISABLE_MAP[d] for d in disable if d in _DISABLE_MAP]
clean_html = template_remover.clean(io.open(options['FILENAME']).read())
results = html_linter.lint(clean_html, exclude=exclude)

path = options['FILENAME']
is_file = os.path.isfile(path)
html_files = [path] if is_file else glob.glob('{}/*.html'.format(path))

results = []
for html_file in html_files:
clean_html = template_remover.clean(io.open(html_file).read())
result = html_linter.lint(clean_html, exclude=exclude)
if result:
results.append(result)

if results:
print(results)
for result in results:
print(result)
return 2

return 0
Expand Down
2 changes: 2 additions & 0 deletions test/data/more_invalid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- Created to test directory globbing -->
<br/>
45 changes: 45 additions & 0 deletions test/test_html_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import io
import os
import subprocess
import unittest

import html_linter
Expand Down Expand Up @@ -570,6 +571,50 @@ def test_valid(self):
self.assertEquals('', html_linter.lint(self.valid_html))


class TestHTML5LinterScript(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.script = os.path.join(os.path.dirname(__file__),
'..',
'scripts',
'html_lint.py')

def call_linter(self, path, should_raise=False):
def _check_output(path):
print(os.environ.copy())
env = {'PYTHONIOENCODING': 'utf-8'} # for pypy3
env.update(os.environ.copy())
return subprocess.check_output(['python', self.script, path],
env=env)

if should_raise:
with self.assertRaises(subprocess.CalledProcessError):
try:
output = _check_output(path)
except subprocess.CalledProcessError as error:
output = error.output.decode('utf8').split('\n')
raise error
else:
output = _check_output(path)

return output

def test_valid(self):
path = os.path.join(os.path.dirname(__file__), 'data', 'valid.html')
output = self.call_linter(path, should_raise=False)
self.assertEquals(0, len(output))

def test_invalid(self):
path = os.path.join(os.path.dirname(__file__), 'data', 'invalid.html')
output = self.call_linter(path, should_raise=True)
self.assertEquals(50, len(output))

def test_glob(self):
path = os.path.join(os.path.dirname(__file__), 'data')
output = self.call_linter(path, should_raise=True)
self.assertEquals(51, len(output))


class TestHTML5LinterUtils(unittest.TestCase):
@staticmethod
def get_linter(last_data, last_data_position):
Expand Down

0 comments on commit fc9781e

Please sign in to comment.