Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
9c959b9d
Commit
9c959b9d
authored
Jul 29, 2016
by
Brian Jacobel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add back JSHint tests
parent
af762733
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
117 additions
and
12 deletions
+117
-12
pavelib/paver_tests/test_jshint.py
+51
-0
pavelib/paver_tests/test_paver_quality.py
+66
-12
No files found.
pavelib/paver_tests/test_jshint.py
0 → 100644
View file @
9c959b9d
"""
Tests for paver quality tasks
"""
import
unittest
from
mock
import
patch
import
pavelib.quality
from
paver.easy
import
BuildFailure
# @TODO Deprecated, remove in favor of ESLint
class
TestPaverJsHint
(
unittest
.
TestCase
):
"""
For testing run_jshint
"""
def
setUp
(
self
):
super
(
TestPaverJsHint
,
self
)
.
setUp
()
# Mock the paver @needs decorator
self
.
_mock_paver_needs
=
patch
.
object
(
pavelib
.
quality
.
run_jshint
,
'needs'
)
.
start
()
self
.
_mock_paver_needs
.
return_value
=
0
# Mock shell commands
patcher
=
patch
(
'pavelib.quality.sh'
)
self
.
_mock_paver_sh
=
patcher
.
start
()
# Cleanup mocks
self
.
addCleanup
(
patcher
.
stop
)
self
.
addCleanup
(
self
.
_mock_paver_needs
.
stop
)
@patch.object
(
pavelib
.
quality
,
'_write_metric'
)
@patch.object
(
pavelib
.
quality
,
'_prepare_report_dir'
)
@patch.object
(
pavelib
.
quality
,
'_get_count_from_last_line'
)
def
test_jshint_violation_number_not_found
(
self
,
mock_count
,
mock_report_dir
,
mock_write_metric
):
# pylint: disable=unused-argument
"""
run_jshint encounters an error parsing the jshint output log
"""
mock_count
.
return_value
=
None
with
self
.
assertRaises
(
BuildFailure
):
pavelib
.
quality
.
run_jshint
(
""
)
@patch.object
(
pavelib
.
quality
,
'_write_metric'
)
@patch.object
(
pavelib
.
quality
,
'_prepare_report_dir'
)
@patch.object
(
pavelib
.
quality
,
'_get_count_from_last_line'
)
def
test_jshint_vanilla
(
self
,
mock_count
,
mock_report_dir
,
mock_write_metric
):
# pylint: disable=unused-argument
"""
jshint finds violations, but a limit was not set
"""
mock_count
.
return_value
=
1
pavelib
.
quality
.
run_jshint
(
""
)
pavelib/paver_tests/test_paver_quality.py
View file @
9c959b9d
...
...
@@ -61,7 +61,7 @@ class TestPaverQualityViolations(unittest.TestCase):
class
TestPaverReportViolationsCounts
(
unittest
.
TestCase
):
"""
For testing utility functions for getting counts from reports for
run_eslint, run_complexity, run_safelint, and run_safecommit_report.
run_
jshint, run_
eslint, run_complexity, run_safelint, and run_safecommit_report.
"""
def
setUp
(
self
):
...
...
@@ -79,19 +79,41 @@ class TestPaverReportViolationsCounts(unittest.TestCase):
self
.
addCleanup
(
self
.
_mock_paver_needs
.
stop
)
self
.
addCleanup
(
os
.
remove
,
self
.
f
.
name
)
# @TODO: Deprecated, remove in favor of ESLint
def
test_get_jshint_violations_count
(
self
):
with
open
(
self
.
f
.
name
,
'w'
)
as
f
:
f
.
write
(
"3000 violations found"
)
actual_count
=
pavelib
.
quality
.
_get_count_from_last_line
(
self
.
f
.
name
,
"jshint"
)
# pylint: disable=protected-access
self
.
assertEqual
(
actual_count
,
3000
)
def
test_get_jshint_violations_no_number_found
(
self
):
with
open
(
self
.
f
.
name
,
'w'
)
as
f
:
f
.
write
(
"Not expected string regex"
)
actual_count
=
pavelib
.
quality
.
_get_count_from_last_line
(
self
.
f
.
name
,
"jshint"
)
# pylint: disable=protected-access
self
.
assertEqual
(
actual_count
,
None
)
def
test_get_jshint_violations_count_truncated_report
(
self
):
"""
A truncated report (i.e. last line is just a violation)
"""
with
open
(
self
.
f
.
name
,
'w'
)
as
f
:
f
.
write
(
"foo/bar/js/fizzbuzz.js: line 45, col 59, Missing semicolon."
)
actual_count
=
pavelib
.
quality
.
_get_count_from_last_line
(
self
.
f
.
name
,
"jshint"
)
# pylint: disable=protected-access
self
.
assertEqual
(
actual_count
,
None
)
def
test_get_eslint_violations_count
(
self
):
with
open
(
self
.
f
.
name
,
'w'
)
as
f
:
f
.
write
(
"3000 violations found"
)
actual_count
=
pavelib
.
quality
.
_get_count_from_last_line
(
self
.
f
.
name
,
"eslint"
)
# pylint: disable=protected-access
self
.
assertEqual
(
actual_count
,
3000
)
def
test_get_violations_no_number_found
(
self
):
def
test_get_
eslint_
violations_no_number_found
(
self
):
with
open
(
self
.
f
.
name
,
'w'
)
as
f
:
f
.
write
(
"Not expected string regex"
)
actual_count
=
pavelib
.
quality
.
_get_count_from_last_line
(
self
.
f
.
name
,
"eslint"
)
# pylint: disable=protected-access
self
.
assertEqual
(
actual_count
,
None
)
def
test_get_violations_count_truncated_report
(
self
):
def
test_get_
eslint_
violations_count_truncated_report
(
self
):
"""
A truncated report (i.e. last line is just a violation)
"""
...
...
@@ -284,10 +306,10 @@ class TestPaverRunQuality(unittest.TestCase):
with
self
.
assertRaises
(
SystemExit
):
pavelib
.
quality
.
run_quality
(
""
)
# Test that pep8, pylint,
and eslint were called
by counting the calls to
# Test that pep8, pylint,
jshint and eslint were called (@TODO remove JSHint)
by counting the calls to
# _get_pep8_violations (for pep8) and sh (for diff-quality pylint & eslint)
self
.
assertEqual
(
_mock_pep8_violations
.
call_count
,
1
)
self
.
assertEqual
(
self
.
_mock_paver_sh
.
call_count
,
2
)
self
.
assertEqual
(
self
.
_mock_paver_sh
.
call_count
,
3
)
@patch
(
'__builtin__.open'
,
mock_open
())
def
test_failure_on_diffquality_pylint
(
self
):
...
...
@@ -305,9 +327,29 @@ class TestPaverRunQuality(unittest.TestCase):
# Test that both pep8 and pylint were called by counting the calls
# Assert that _get_pep8_violations (which calls "pep8") is called once
self
.
assertEqual
(
_mock_pep8_violations
.
call_count
,
1
)
# And assert that sh was called twice (for the calls to pylint & eslint). This means that even in
# the event of a diff-quality pylint failure, eslint is still called.
self
.
assertEqual
(
self
.
_mock_paver_sh
.
call_count
,
2
)
# And assert that sh was called 3x (for the calls to pylint & jshint & eslint). (@TODO remove JSHint)
# This means that even in the event of a diff-quality pylint failure, eslint is still called.
self
.
assertEqual
(
self
.
_mock_paver_sh
.
call_count
,
3
)
# @TODO: Deprecated, remove in favor of ESLint
@patch
(
'__builtin__.open'
,
mock_open
())
def
test_failure_on_diffquality_jshint
(
self
):
"""
If diff-quality fails on jshint, the paver task should also fail
"""
# Underlying sh call must fail when it is running the jshint diff-quality task
self
.
_mock_paver_sh
.
side_effect
=
CustomShMock
()
.
fail_on_jshint
_mock_pep8_violations
=
MagicMock
(
return_value
=
(
0
,
[]))
with
patch
(
'pavelib.quality._get_pep8_violations'
,
_mock_pep8_violations
):
with
self
.
assertRaises
(
SystemExit
):
pavelib
.
quality
.
run_quality
(
""
)
self
.
assertRaises
(
BuildFailure
)
# Test that both pep8 and pylint were called by counting the calls
# Assert that _get_pep8_violations (which calls "pep8") is called once
self
.
assertEqual
(
_mock_pep8_violations
.
call_count
,
1
)
# And assert that sh was called 3x (for the calls to pep8 , jshint and pylint) @TODO remove this test
self
.
assertEqual
(
self
.
_mock_paver_sh
.
call_count
,
3
)
@patch
(
'__builtin__.open'
,
mock_open
())
def
test_failure_on_diffquality_eslint
(
self
):
...
...
@@ -325,8 +367,8 @@ class TestPaverRunQuality(unittest.TestCase):
# Test that both pep8 and pylint were called by counting the calls
# Assert that _get_pep8_violations (which calls "pep8") is called once
self
.
assertEqual
(
_mock_pep8_violations
.
call_count
,
1
)
# And assert that sh was called
twice (for the calls to pep8 and pylint)
self
.
assertEqual
(
self
.
_mock_paver_sh
.
call_count
,
2
)
# And assert that sh was called
3x (for the calls to pep8, jshint and pylint) @TODO, remove jshint and decrement
self
.
assertEqual
(
self
.
_mock_paver_sh
.
call_count
,
3
)
@patch
(
'__builtin__.open'
,
mock_open
())
def
test_other_exception
(
self
):
...
...
@@ -349,8 +391,8 @@ class TestPaverRunQuality(unittest.TestCase):
pavelib
.
quality
.
run_quality
(
""
)
# Assert that _get_pep8_violations (which calls "pep8") is called once
self
.
assertEqual
(
_mock_pep8_violations
.
call_count
,
1
)
# And assert that sh was called
twice (for the call to "pylint" & "eslint"
)
self
.
assertEqual
(
self
.
_mock_paver_sh
.
call_count
,
2
)
# And assert that sh was called
3x (for the call to "pylint" & "jshint" & "eslint") (@TODO, remove jshint
)
self
.
assertEqual
(
self
.
_mock_paver_sh
.
call_count
,
3
)
class
CustomShMock
(
object
):
...
...
@@ -370,6 +412,18 @@ class CustomShMock(object):
else
:
return
# @TODO: Deprecated, remove in favor of ESLint
def
fail_on_jshint
(
self
,
arg
):
"""
For our tests, we need the call for diff-quality running pep8 reports to fail, since that is what
is going to fail when we pass in a percentage ("p") requirement.
"""
if
"jshint"
in
arg
:
# Essentially mock diff-quality exiting with 1
paver
.
easy
.
sh
(
"exit 1"
)
else
:
return
def
fail_on_eslint
(
self
,
arg
):
"""
For our tests, we need the call for diff-quality running pep8 reports to fail, since that is what
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment