Commit 87495891 by Sarina Canelake

Fix some simple pep8 and pylint violations

parent 2c9585ea
...@@ -627,7 +627,6 @@ class FileSubmission(InputTypeBase): ...@@ -627,7 +627,6 @@ class FileSubmission(InputTypeBase):
template = "filesubmission.html" template = "filesubmission.html"
tags = ['filesubmission'] tags = ['filesubmission']
@staticmethod @staticmethod
def parse_files(files): def parse_files(files):
""" """
...@@ -684,21 +683,21 @@ class CodeInput(InputTypeBase): ...@@ -684,21 +683,21 @@ class CodeInput(InputTypeBase):
# non-codemirror editor. # non-codemirror editor.
] ]
@classmethod @classmethod
def get_attributes(cls): def get_attributes(cls):
""" """
Convert options to a convenient format. Convert options to a convenient format.
""" """
return [Attribute('rows', '30'), return [
Attribute('cols', '80'), Attribute('rows', '30'),
Attribute('hidden', ''), Attribute('cols', '80'),
Attribute('hidden', ''),
# For CodeMirror
Attribute('mode', 'python'), # For CodeMirror
Attribute('linenumbers', 'true'), Attribute('mode', 'python'),
# Template expects tabsize to be an int it can do math with Attribute('linenumbers', 'true'),
Attribute('tabsize', 4, transform=int), # Template expects tabsize to be an int it can do math with
Attribute('tabsize', 4, transform=int),
] ]
def setup_code_response_rendering(self): def setup_code_response_rendering(self):
...@@ -753,7 +752,6 @@ class MatlabInput(CodeInput): ...@@ -753,7 +752,6 @@ class MatlabInput(CodeInput):
template = "matlabinput.html" template = "matlabinput.html"
tags = ['matlabinput'] tags = ['matlabinput']
def setup(self): def setup(self):
""" """
Handle matlab-specific parsing Handle matlab-specific parsing
...@@ -1049,7 +1047,7 @@ class ChemicalEquationInput(InputTypeBase): ...@@ -1049,7 +1047,7 @@ class ChemicalEquationInput(InputTypeBase):
Can set size of text field. Can set size of text field.
""" """
return [Attribute('size', '20'), return [Attribute('size', '20'),
Attribute('label', ''),] Attribute('label', ''), ]
def _extra_context(self): def _extra_context(self):
""" """
......
...@@ -132,7 +132,7 @@ try: ...@@ -132,7 +132,7 @@ try:
# Markdown 2.1.0 changed from 2.0.3. We try importing the new version first, # Markdown 2.1.0 changed from 2.0.3. We try importing the new version first,
# but import the 2.0.3 version if it fails # but import the 2.0.3 version if it fails
from markdown.util import etree from markdown.util import etree
except: except: # pylint: disable=bare-except
from markdown import etree from markdown import etree
...@@ -172,21 +172,21 @@ class VideoExtension(markdown.Extension): ...@@ -172,21 +172,21 @@ class VideoExtension(markdown.Extension):
def extendMarkdown(self, md, md_globals): def extendMarkdown(self, md, md_globals):
self.add_inline(md, 'bliptv', Bliptv, self.add_inline(md, 'bliptv', Bliptv,
r'([^(]|^)http://(\w+\.|)blip.tv/file/get/(?P<bliptvfile>\S+.flv)') r'([^(]|^)http://(\w+\.|)blip.tv/file/get/(?P<bliptvfile>\S+.flv)')
self.add_inline(md, 'dailymotion', Dailymotion, self.add_inline(md, 'dailymotion', Dailymotion,
r'([^(]|^)http://www\.dailymotion\.com/(?P<dailymotionid>\S+)') r'([^(]|^)http://www\.dailymotion\.com/(?P<dailymotionid>\S+)')
self.add_inline(md, 'gametrailers', Gametrailers, self.add_inline(md, 'gametrailers', Gametrailers,
r'([^(]|^)http://www.gametrailers.com/video/[a-z0-9-]+/(?P<gametrailersid>\d+)') r'([^(]|^)http://www.gametrailers.com/video/[a-z0-9-]+/(?P<gametrailersid>\d+)')
self.add_inline(md, 'metacafe', Metacafe, self.add_inline(md, 'metacafe', Metacafe,
r'([^(]|^)http://www\.metacafe\.com/watch/(?P<metacafeid>\S+)/') r'([^(]|^)http://www\.metacafe\.com/watch/(?P<metacafeid>\S+)/')
self.add_inline(md, 'veoh', Veoh, self.add_inline(md, 'veoh', Veoh,
r'([^(]|^)http://www\.veoh\.com/\S*(#watch%3D|watch/)(?P<veohid>\w+)') r'([^(]|^)http://www\.veoh\.com/\S*(#watch%3D|watch/)(?P<veohid>\w+)')
self.add_inline(md, 'vimeo', Vimeo, self.add_inline(md, 'vimeo', Vimeo,
r'([^(]|^)http://(www.|)vimeo\.com/(?P<vimeoid>\d+)\S*') r'([^(]|^)http://(www.|)vimeo\.com/(?P<vimeoid>\d+)\S*')
self.add_inline(md, 'yahoo', Yahoo, self.add_inline(md, 'yahoo', Yahoo,
r'([^(]|^)http://video\.yahoo\.com/watch/(?P<yahoovid>\d+)/(?P<yahooid>\d+)') r'([^(]|^)http://video\.yahoo\.com/watch/(?P<yahoovid>\d+)/(?P<yahooid>\d+)')
self.add_inline(md, 'youtube', Youtube, self.add_inline(md, 'youtube', Youtube,
r'([^(]|^)http://www\.youtube\.com/watch\?\S*v=(?P<youtubeargs>[A-Za-z0-9_&=-]+)\S*') r'([^(]|^)http://www\.youtube\.com/watch\?\S*v=(?P<youtubeargs>[A-Za-z0-9_&=-]+)\S*')
class Bliptv(markdown.inlinepatterns.Pattern): class Bliptv(markdown.inlinepatterns.Pattern):
...@@ -247,7 +247,7 @@ class Yahoo(markdown.inlinepatterns.Pattern): ...@@ -247,7 +247,7 @@ class Yahoo(markdown.inlinepatterns.Pattern):
param = etree.Element('param') param = etree.Element('param')
param.set('name', 'flashVars') param.set('name', 'flashVars')
param.set('value', "id=%s&vid=%s" % (m.group('yahooid'), param.set('value', "id=%s&vid=%s" % (m.group('yahooid'),
m.group('yahoovid'))) m.group('yahoovid')))
obj.append(param) obj.append(param)
return obj return obj
...@@ -261,24 +261,24 @@ class Youtube(markdown.inlinepatterns.Pattern): ...@@ -261,24 +261,24 @@ class Youtube(markdown.inlinepatterns.Pattern):
def flash_object(url, width, height): def flash_object(url, width, height):
obj = etree.Element('object') obj = etree.Element('object')
obj.set('type', 'application/x-shockwave-flash') obj.set('type', 'application/x-shockwave-flash')
obj.set('width', width) obj.set('width', width)
obj.set('height', height) obj.set('height', height)
obj.set('data', url) obj.set('data', url)
param = etree.Element('param') param = etree.Element('param')
param.set('name', 'movie') param.set('name', 'movie')
param.set('value', url) param.set('value', url)
obj.append(param) obj.append(param)
param = etree.Element('param') param = etree.Element('param')
param.set('name', 'allowFullScreen') param.set('name', 'allowFullScreen')
param.set('value', 'true') param.set('value', 'true')
obj.append(param) obj.append(param)
#param = etree.Element('param') #param = etree.Element('param')
#param.set('name', 'allowScriptAccess') #param.set('name', 'allowScriptAccess')
#param.set('value', 'sameDomain') #param.set('value', 'sameDomain')
#obj.append(param) #obj.append(param)
return obj return obj
def makeExtension(configs=None): def makeExtension(configs=None):
......
...@@ -14,12 +14,14 @@ from courseware.management.commands.clean_history import StudentModuleHistoryCle ...@@ -14,12 +14,14 @@ from courseware.management.commands.clean_history import StudentModuleHistoryCle
# In lots of places in this file, smhc == StudentModuleHistoryCleaner # In lots of places in this file, smhc == StudentModuleHistoryCleaner
def parse_date(sdate): def parse_date(sdate):
"""Parse a string date into a datetime.""" """Parse a string date into a datetime."""
parsed = dateutil.parser.parse(sdate) parsed = dateutil.parser.parse(sdate)
parsed = parsed.replace(tzinfo=dateutil.tz.gettz('UTC')) parsed = parsed.replace(tzinfo=dateutil.tz.gettz('UTC'))
return parsed return parsed
class SmhcSayStubbed(StudentModuleHistoryCleaner): class SmhcSayStubbed(StudentModuleHistoryCleaner):
"""StudentModuleHistoryCleaner, but with .say() stubbed for testing.""" """StudentModuleHistoryCleaner, but with .say() stubbed for testing."""
def __init__(self, **kwargs): def __init__(self, **kwargs):
...@@ -110,7 +112,8 @@ class HistoryCleanerTest(TransactionTestCase): ...@@ -110,7 +112,8 @@ class HistoryCleanerTest(TransactionTestCase):
""" """
cursor = connection.cursor() cursor = connection.cursor()
cursor.executemany(""" cursor.executemany(
"""
INSERT INTO courseware_studentmodulehistory INSERT INTO courseware_studentmodulehistory
(id, created, student_module_id) (id, created, student_module_id)
VALUES (%s, %s, %s) VALUES (%s, %s, %s)
...@@ -191,8 +194,8 @@ class HistoryCleanerNoDbTest(HistoryCleanerTest): ...@@ -191,8 +194,8 @@ class HistoryCleanerNoDbTest(HistoryCleanerTest):
def test_a_bunch_of_rows(self): def test_a_bunch_of_rows(self):
smhc = SmhcDbMocked() smhc = SmhcDbMocked()
smhc.set_rows([ smhc.set_rows([
( 4, "2013-07-13 16:30:00.000"), # keep (4, "2013-07-13 16:30:00.000"), # keep
( 8, "2013-07-13 16:30:01.100"), (8, "2013-07-13 16:30:01.100"),
(15, "2013-07-13 16:30:01.200"), (15, "2013-07-13 16:30:01.200"),
(16, "2013-07-13 16:30:01.300"), # keep (16, "2013-07-13 16:30:01.300"), # keep
(23, "2013-07-13 16:30:02.400"), (23, "2013-07-13 16:30:02.400"),
...@@ -212,8 +215,8 @@ class HistoryCleanerWitDbTest(HistoryCleanerTest): ...@@ -212,8 +215,8 @@ class HistoryCleanerWitDbTest(HistoryCleanerTest):
# Cleaning a student_module_id with no history leaves the db unchanged. # Cleaning a student_module_id with no history leaves the db unchanged.
smhc = SmhcSayStubbed() smhc = SmhcSayStubbed()
self.write_history([ self.write_history([
( 4, "2013-07-13 16:30:00.000", 11), # keep (4, "2013-07-13 16:30:00.000", 11), # keep
( 8, "2013-07-13 16:30:01.100", 11), (8, "2013-07-13 16:30:01.100", 11),
(15, "2013-07-13 16:30:01.200", 11), (15, "2013-07-13 16:30:01.200", 11),
(16, "2013-07-13 16:30:01.300", 11), # keep (16, "2013-07-13 16:30:01.300", 11), # keep
(23, "2013-07-13 16:30:02.400", 11), (23, "2013-07-13 16:30:02.400", 11),
...@@ -225,8 +228,8 @@ class HistoryCleanerWitDbTest(HistoryCleanerTest): ...@@ -225,8 +228,8 @@ class HistoryCleanerWitDbTest(HistoryCleanerTest):
smhc.clean_one_student_module(22) smhc.clean_one_student_module(22)
self.assert_said(smhc, "No history for student_module_id 22") self.assert_said(smhc, "No history for student_module_id 22")
self.assert_history([ self.assert_history([
( 4, "2013-07-13 16:30:00.000", 11), # keep (4, "2013-07-13 16:30:00.000", 11), # keep
( 8, "2013-07-13 16:30:01.100", 11), (8, "2013-07-13 16:30:01.100", 11),
(15, "2013-07-13 16:30:01.200", 11), (15, "2013-07-13 16:30:01.200", 11),
(16, "2013-07-13 16:30:01.300", 11), # keep (16, "2013-07-13 16:30:01.300", 11), # keep
(23, "2013-07-13 16:30:02.400", 11), (23, "2013-07-13 16:30:02.400", 11),
...@@ -239,8 +242,8 @@ class HistoryCleanerWitDbTest(HistoryCleanerTest): ...@@ -239,8 +242,8 @@ class HistoryCleanerWitDbTest(HistoryCleanerTest):
# Cleaning a student_module_id with 8 records, 4 to delete. # Cleaning a student_module_id with 8 records, 4 to delete.
smhc = SmhcSayStubbed() smhc = SmhcSayStubbed()
self.write_history([ self.write_history([
( 4, "2013-07-13 16:30:00.000", 11), # keep (4, "2013-07-13 16:30:00.000", 11), # keep
( 8, "2013-07-13 16:30:01.100", 11), (8, "2013-07-13 16:30:01.100", 11),
(15, "2013-07-13 16:30:01.200", 11), (15, "2013-07-13 16:30:01.200", 11),
(16, "2013-07-13 16:30:01.300", 11), # keep (16, "2013-07-13 16:30:01.300", 11), # keep
(17, "2013-07-13 16:30:01.310", 22), # other student_module_id! (17, "2013-07-13 16:30:01.310", 22), # other student_module_id!
...@@ -253,7 +256,7 @@ class HistoryCleanerWitDbTest(HistoryCleanerTest): ...@@ -253,7 +256,7 @@ class HistoryCleanerWitDbTest(HistoryCleanerTest):
smhc.clean_one_student_module(11) smhc.clean_one_student_module(11)
self.assert_said(smhc, "Deleting 4 rows of 8 for student_module_id 11") self.assert_said(smhc, "Deleting 4 rows of 8 for student_module_id 11")
self.assert_history([ self.assert_history([
( 4, "2013-07-13 16:30:00.000", 11), # keep (4, "2013-07-13 16:30:00.000", 11), # keep
(16, "2013-07-13 16:30:01.300", 11), # keep (16, "2013-07-13 16:30:01.300", 11), # keep
(17, "2013-07-13 16:30:01.310", 22), # other student_module_id! (17, "2013-07-13 16:30:01.310", 22), # other student_module_id!
(98, "2013-07-13 16:30:02.600", 11), # keep (98, "2013-07-13 16:30:02.600", 11), # keep
...@@ -261,12 +264,12 @@ class HistoryCleanerWitDbTest(HistoryCleanerTest): ...@@ -261,12 +264,12 @@ class HistoryCleanerWitDbTest(HistoryCleanerTest):
]) ])
def test_a_bunch_of_rows_dry_run(self): def test_a_bunch_of_rows_dry_run(self):
# Cleaning a student_module_id with 8 records, 4 to delete, # Cleaning a student_module_id with 8 records, 4 to delete,
# but don't really do it. # but don't really do it.
smhc = SmhcSayStubbed(dry_run=True) smhc = SmhcSayStubbed(dry_run=True)
self.write_history([ self.write_history([
( 4, "2013-07-13 16:30:00.000", 11), # keep (4, "2013-07-13 16:30:00.000", 11), # keep
( 8, "2013-07-13 16:30:01.100", 11), (8, "2013-07-13 16:30:01.100", 11),
(15, "2013-07-13 16:30:01.200", 11), (15, "2013-07-13 16:30:01.200", 11),
(16, "2013-07-13 16:30:01.300", 11), # keep (16, "2013-07-13 16:30:01.300", 11), # keep
(23, "2013-07-13 16:30:02.400", 11), (23, "2013-07-13 16:30:02.400", 11),
...@@ -278,8 +281,8 @@ class HistoryCleanerWitDbTest(HistoryCleanerTest): ...@@ -278,8 +281,8 @@ class HistoryCleanerWitDbTest(HistoryCleanerTest):
smhc.clean_one_student_module(11) smhc.clean_one_student_module(11)
self.assert_said(smhc, "Would have deleted 4 rows of 8 for student_module_id 11") self.assert_said(smhc, "Would have deleted 4 rows of 8 for student_module_id 11")
self.assert_history([ self.assert_history([
( 4, "2013-07-13 16:30:00.000", 11), # keep (4, "2013-07-13 16:30:00.000", 11), # keep
( 8, "2013-07-13 16:30:01.100", 11), (8, "2013-07-13 16:30:01.100", 11),
(15, "2013-07-13 16:30:01.200", 11), (15, "2013-07-13 16:30:01.200", 11),
(16, "2013-07-13 16:30:01.300", 11), # keep (16, "2013-07-13 16:30:01.300", 11), # keep
(23, "2013-07-13 16:30:02.400", 11), (23, "2013-07-13 16:30:02.400", 11),
...@@ -400,7 +403,8 @@ class HistoryCleanerMainTest(HistoryCleanerTest): ...@@ -400,7 +403,8 @@ class HistoryCleanerMainTest(HistoryCleanerTest):
(1, "2013-07-15 11:47:00.000", 1), (1, "2013-07-15 11:47:00.000", 1),
]) ])
smhc.main() smhc.main()
self.assert_said(smhc, self.assert_said(
smhc,
'Last student_module_id is 1', 'Last student_module_id is 1',
'No stored state', 'No stored state',
'(not really cleaning 0)', '(not really cleaning 0)',
...@@ -420,7 +424,8 @@ class HistoryCleanerMainTest(HistoryCleanerTest): ...@@ -420,7 +424,8 @@ class HistoryCleanerMainTest(HistoryCleanerTest):
(5, "2013-07-15 15:04:00.000", 26), (5, "2013-07-15 15:04:00.000", 26),
]) ])
smhc.main() smhc.main()
self.assert_said(smhc, self.assert_said(
smhc,
'Last student_module_id is 26', 'Last student_module_id is 26',
'Loaded stored state: {"next_student_module_id": 25}', 'Loaded stored state: {"next_student_module_id": 25}',
'(not really cleaning 25)', '(not really cleaning 25)',
...@@ -441,7 +446,8 @@ class HistoryCleanerMainTest(HistoryCleanerTest): ...@@ -441,7 +446,8 @@ class HistoryCleanerMainTest(HistoryCleanerTest):
(8, "2013-07-15 15:04:00.000", 29), (8, "2013-07-15 15:04:00.000", 29),
]) ])
smhc.main(batch_size=3) smhc.main(batch_size=3)
self.assert_said(smhc, self.assert_said(
smhc,
'Last student_module_id is 29', 'Last student_module_id is 29',
'Loaded stored state: {"next_student_module_id": 25}', 'Loaded stored state: {"next_student_module_id": 25}',
'(not really cleaning 25)', '(not really cleaning 25)',
...@@ -467,7 +473,8 @@ class HistoryCleanerMainTest(HistoryCleanerTest): ...@@ -467,7 +473,8 @@ class HistoryCleanerMainTest(HistoryCleanerTest):
(8, "2013-07-15 15:04:00.000", 29), (8, "2013-07-15 15:04:00.000", 29),
]) ])
smhc.main(batch_size=3) smhc.main(batch_size=3)
self.assert_said(smhc, self.assert_said(
smhc,
'Last student_module_id is 29', 'Last student_module_id is 29',
'Loaded stored state: {"next_student_module_id": 25}', 'Loaded stored state: {"next_student_module_id": 25}',
'(not really cleaning 25)', '(not really cleaning 25)',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment