Skip to content

Commit

Permalink
TE-2528 Upgrade testing dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbowman committed Apr 25, 2018
1 parent ee1eaaf commit 9477ad2
Show file tree
Hide file tree
Showing 19 changed files with 158 additions and 180 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ cover_html/
reports/
jscover.log
jscover.log.*
.pytest_cache/
.tddium*
common/test/data/test_unicode/static/
test_root/courses/
Expand Down
90 changes: 25 additions & 65 deletions common/djangoapps/track/backends/tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,73 +6,33 @@
import logging
import datetime

from django.test import TestCase

from track.backends.logger import LoggerBackend


class TestLoggerBackend(TestCase):
def setUp(self):
super(TestLoggerBackend, self).setUp()
self.handler = MockLoggingHandler()
self.handler.setLevel(logging.INFO)

logger_name = 'track.backends.logger.test'
logger = logging.getLogger(logger_name)
logger.addHandler(self.handler)

self.backend = LoggerBackend(name=logger_name)

def test_logger_backend(self):
self.handler.reset()

# Send a couple of events and check if they were recorded
# by the logger. The events are serialized to JSON.

event = {
'test': True,
'time': datetime.datetime(2012, 05, 01, 07, 27, 01, 200),
'date': datetime.date(2012, 05, 07),
}

self.backend.send(event)
self.backend.send(event)

saved_events = [json.loads(e) for e in self.handler.messages['info']]

unpacked_event = {
'test': True,
'time': '2012-05-01T07:27:01.000200+00:00',
'date': '2012-05-07'
}

self.assertEqual(saved_events[0], unpacked_event)
self.assertEqual(saved_events[1], unpacked_event)


class MockLoggingHandler(logging.Handler):
def test_logger_backend(caplog):
"""
Mock logging handler.
Stores records in a dictionry of lists by level.
Send a couple of events and check if they were recorded
by the logger. The events are serialized to JSON.
"""

def __init__(self, *args, **kwargs):
super(MockLoggingHandler, self).__init__(*args, **kwargs)
self.messages = None
self.reset()

def emit(self, record):
level = record.levelname.lower()
message = record.getMessage()
self.messages[level].append(message)

def reset(self):
self.messages = {
'debug': [],
'info': [],
'warning': [],
'error': [],
'critical': [],
}
caplog.set_level(logging.INFO)
logger_name = 'track.backends.logger.test'
backend = LoggerBackend(name=logger_name)
event = {
'test': True,
'time': datetime.datetime(2012, 5, 1, 7, 27, 1, 200),
'date': datetime.date(2012, 5, 7),
}

backend.send(event)
backend.send(event)

saved_events = [json.loads(e[2]) for e in caplog.record_tuples if e[0] == logger_name]

unpacked_event = {
'test': True,
'time': '2012-05-01T07:27:01.000200+00:00',
'date': '2012-05-07'
}

assert saved_events[0] == unpacked_event
assert saved_events[1] == unpacked_event
2 changes: 1 addition & 1 deletion common/lib/capa/capa/tests/response_xml_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def build_xml(self, **kwargs):
# Add input elements
for __ in range(int(num_inputs)):
input_element = self.create_input_element(**kwargs)
if not None == input_element:
if input_element is not None:
response_element.append(input_element)

# The problem has an explanation of the solution
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""
from datetime import datetime, timedelta
import ddt
from django.test import TestCase
from nose.plugins.attrib import attr
import pytz
import unittest
Expand Down Expand Up @@ -84,7 +85,7 @@ def test_find(self):

@attr('mongo')
@ddt.ddt
class TestMongoAssetMetadataStorage(unittest.TestCase):
class TestMongoAssetMetadataStorage(TestCase):
"""
Tests for storing/querying course asset metadata.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@

from tempfile import mkdtemp
from shutil import rmtree
from unittest import TestCase, skip
from unittest import skip
import ddt
from django.test import TestCase

from xmodule.modulestore.xml_importer import import_course_from_xml
from xmodule.modulestore.xml_exporter import export_course_to_xml
Expand Down
3 changes: 2 additions & 1 deletion common/lib/xmodule/xmodule/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import unittest

from contextlib import contextmanager, nested
from django.test import TestCase
from functools import wraps
from mock import Mock
from path import Path as path
Expand Down Expand Up @@ -255,7 +256,7 @@ def raise_assertion_errors(self):
raise BulkAssertionError(self._assertion_errors)


class BulkAssertionTest(unittest.TestCase):
class BulkAssertionTest(TestCase):
"""
This context manager provides a _BulkAssertionManager to assert with,
and then calls `raise_assertion_errors` at the end of the block to validate all
Expand Down
2 changes: 1 addition & 1 deletion docs/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ To view test coverage:
Python Code Style Quality
-------------------------

To view Python code style quality (including pep8 and pylint violations) run this command::
To view Python code style quality (including PEP 8 and pylint violations) run this command::

paver run_quality

Expand Down
5 changes: 0 additions & 5 deletions lms/djangoapps/courseware/features/lti.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,6 @@ def add_correct_lti_to_course(_step, fields):
metadata=metadata,
)

world.scenario_dict['LTI'].TEST_BASE_PATH = '{host}:{port}'.format(
host=world.browser.host,
port=world.browser.port,
)

visit_scenario_item('LTI')


Expand Down
4 changes: 2 additions & 2 deletions pavelib/paver_tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def fail_on_pylint(*args):

def fail_on_npm_install(*args):
"""
For our tests, we need the call for diff-quality running pep8 reports to fail, since that is what
For our tests, we need the call for diff-quality running pycodestyle reports to fail, since that is what
is going to fail when we pass in a percentage ("p") requirement.
"""
if "npm install" in args[0]:
Expand All @@ -102,7 +102,7 @@ def fail_on_npm_install(*args):

def unexpected_fail_on_npm_install(*args):
"""
For our tests, we need the call for diff-quality running pep8 reports to fail, since that is what
For our tests, we need the call for diff-quality running pycodestyle reports to fail, since that is what
is going to fail when we pass in a percentage ("p") requirement.
"""
if "npm install" in args[0]:
Expand Down
18 changes: 9 additions & 9 deletions pavelib/quality.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# coding=utf-8

"""
Check code quality using pep8, pylint, and diff_quality.
Check code quality using pycodestyle, pylint, and diff_quality.
"""
import json
import os
Expand Down Expand Up @@ -206,8 +206,8 @@ def _count_pylint_violations(report_file):

def _get_pep8_violations(clean=True):
"""
Runs pep8. Returns a tuple of (number_of_violations, violations_string)
where violations_string is a string of all pep8 violations found, separated
Runs pycodestyle. Returns a tuple of (number_of_violations, violations_string)
where violations_string is a string of all PEP 8 violations found, separated
by new lines.
"""
report_dir = (Env.REPORT_DIR / 'pep8')
Expand All @@ -220,16 +220,16 @@ def _get_pep8_violations(clean=True):
Env.METRICS_DIR.makedirs_p()

if not report.exists():
sh('pep8 . | tee {} -a'.format(report))
sh('pycodestyle . | tee {} -a'.format(report))

violations_list = _pep8_violations(report)

return (len(violations_list), violations_list)
return len(violations_list), violations_list


def _pep8_violations(report_file):
"""
Returns the list of all pep8 violations in the given report_file.
Returns the list of all PEP 8 violations in the given report_file.
"""
with open(report_file) as f:
return f.readlines()
Expand All @@ -243,14 +243,14 @@ def _pep8_violations(report_file):
@timed
def run_pep8(options): # pylint: disable=unused-argument
"""
Run pep8 on system code.
Run pycodestyle on system code.
Fail the task if any violations are found.
"""
(count, violations_list) = _get_pep8_violations()
violations_list = ''.join(violations_list)

# Print number of violations to log
violations_count_str = "Number of pep8 violations: {count}".format(count=count)
violations_count_str = "Number of PEP 8 violations: {count}".format(count=count)
print violations_count_str
print violations_list

Expand All @@ -261,7 +261,7 @@ def run_pep8(options): # pylint: disable=unused-argument

# Fail if any violations are found
if count:
failure_string = "FAILURE: Too many pep8 violations. " + violations_count_str
failure_string = "FAILURE: Too many PEP 8 violations. " + violations_count_str
failure_string += "\n\nViolations:\n{violations_list}".format(violations_list=violations_list)
raise BuildFailure(failure_string)

Expand Down
6 changes: 3 additions & 3 deletions requirements/edx/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
# as development.in or testing.in instead.

analytics-python==1.1.0 # Used for Segment analytics
attrs==17.2.0 # Reduces boilerplate code involving class attributes
attrs # Reduces boilerplate code involving class attributes
Babel==1.3 # Internationalization utilities, used for date formatting in a few places
bleach==1.4 # Allowed-list-based HTML sanitizing library that escapes or strips markup and attributes; used for capa and LTI
boto==2.39.0 # Deprecated version of the AWS SDK; we should stop using this
Expand Down Expand Up @@ -63,7 +63,7 @@ django-waffle==0.12.0
django-webpack-loader==0.4.1
djangorestframework-jwt
dogapi==1.2.1 # Python bindings to Datadog's API, for metrics gathering
edx-ace
edx-ace==0.1.6
edx-analytics-data-api-client
edx-ccx-keys
edx-celeryutils
Expand Down Expand Up @@ -121,7 +121,7 @@ pynliner==0.5.2 # Inlines CSS styles into HTML for email not
python-dateutil==2.4
python-Levenshtein
python-openid
python-saml
python-saml==2.4.0
pyuca==1.1 # For more accurate sorting of translated country names in django-countries
reportlab==3.1.44 # Used for shopping cart's pdf invoice/receipt generation
social-auth-app-django==1.2.0
Expand Down
6 changes: 3 additions & 3 deletions requirements/edx/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ appdirs==1.4.3 # via fs
argh==0.26.2
argparse==1.4.0
asn1crypto==0.24.0
attrs==17.2.0
attrs==17.4.0
babel==1.3
beautifulsoup==3.2.1 # via pynliner
billiard==3.3.0.23 # via celery
Expand All @@ -70,7 +70,7 @@ django-appconf==1.0.2 # via django-statici18n
django-babel-underscore==0.5.2
django-babel==0.6.2 # via django-babel-underscore
django-birdcage==1.0.0
django-braces==1.12.0 # via django-oauth-toolkit
django-braces==1.13.0 # via django-oauth-toolkit
django-classy-tags==0.8.0 # via django-sekizai
django-config-models==0.1.8
django-cors-headers==2.1.0
Expand Down Expand Up @@ -211,7 +211,7 @@ sailthru-client==2.2.3
scipy==0.14.0
shapely==1.2.16
shortuuid==0.5.0 # via edx-django-oauth2-provider
simplejson==3.13.2 # via dogapi, mailsnake, sailthru-client, zendesk
simplejson==3.14.0 # via dogapi, mailsnake, sailthru-client, zendesk
six==1.11.0
slumber==0.7.1 # via edx-rest-api-client
social-auth-app-django==1.2.0
Expand Down
Loading

0 comments on commit 9477ad2

Please sign in to comment.