Skip to content

Commit

Permalink
Fix part of oppia#5476: Add checks to detect spaces in docstring (opp…
Browse files Browse the repository at this point in the history
  • Loading branch information
Rishav Chakraborty authored and DubeySandeep committed Feb 22, 2019
1 parent 6dc966d commit 0d676f9
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 20 deletions.
2 changes: 1 addition & 1 deletion core/controllers/acl_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -1825,7 +1825,7 @@ def can_user_edit_skill(user, skill_rights):
return False

def test_can_edit_skill(self, skill_id, **kwargs):
""" Test to see if user can edit a given skill by checking if
"""Test to see if user can edit a given skill by checking if
logged in and using can_user_edit_skill.
Args:
Expand Down
2 changes: 1 addition & 1 deletion core/controllers/admin_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_change_about_page_config_property(self):


class GenerateDummyExplorationsTest(test_utils.GenericTestBase):
""" Test the conditions for generation of dummy explorations."""
"""Test the conditions for generation of dummy explorations."""

def test_generate_count_greater_than_publish_count(self):
self.signup(self.ADMIN_EMAIL, self.ADMIN_USERNAME)
Expand Down
2 changes: 1 addition & 1 deletion core/controllers/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def get(self):


class ProfilePictureHandlerByUsernameHandler(base.BaseHandler):
""" Provides the dataURI of the profile picture of the specified user,
"""Provides the dataURI of the profile picture of the specified user,
or None if no user picture is uploaded for the user with that ID.
"""

Expand Down
2 changes: 1 addition & 1 deletion core/controllers/translator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def setUp(self):
self.csrf_token = self.get_csrf_token_from_response(response)

def test_firsttime_translation_tutorial(self):
""" Testing of the firsttime translation tutorial http requests."""
"""Testing of the firsttime translation tutorial http requests."""
# Check if method returns 200 http status.
self.post_json(
'/createhandler/started_translation_tutorial_event/%s'
Expand Down
18 changes: 9 additions & 9 deletions core/domain/exp_domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -2571,7 +2571,7 @@ def _convert_v16_dict_to_v17_dict(cls, exploration_dict):

@classmethod
def _convert_v17_dict_to_v18_dict(cls, exploration_dict):
""" Converts a v17 exploration dict into a v18 exploration dict.
"""Converts a v17 exploration dict into a v18 exploration dict.
Adds auto_tts_enabled property.
"""
Expand All @@ -2586,7 +2586,7 @@ def _convert_v17_dict_to_v18_dict(cls, exploration_dict):

@classmethod
def _convert_v18_dict_to_v19_dict(cls, exploration_dict):
""" Converts a v18 exploration dict into a v19 exploration dict.
"""Converts a v18 exploration dict into a v19 exploration dict.
Adds audio translations to feedback, hints, and solutions.
"""
Expand All @@ -2600,7 +2600,7 @@ def _convert_v18_dict_to_v19_dict(cls, exploration_dict):

@classmethod
def _convert_v19_dict_to_v20_dict(cls, exploration_dict):
""" Converts a v19 exploration dict into a v20 exploration dict.
"""Converts a v19 exploration dict into a v20 exploration dict.
Introduces a correctness property at the top level, and changes each
answer group's "correct" field to "labelled_as_correct" instead.
Expand All @@ -2617,7 +2617,7 @@ def _convert_v19_dict_to_v20_dict(cls, exploration_dict):

@classmethod
def _convert_v20_dict_to_v21_dict(cls, exploration_dict):
""" Converts a v20 exploration dict into a v21 exploration dict.
"""Converts a v20 exploration dict into a v21 exploration dict.
Adds a refresher_exploration_id field to each answer group outcome, and
to the default outcome (if it exists).
Expand All @@ -2632,7 +2632,7 @@ def _convert_v20_dict_to_v21_dict(cls, exploration_dict):

@classmethod
def _convert_v21_dict_to_v22_dict(cls, exploration_dict):
""" Converts a v21 exploration dict into a v22 exploration dict.
"""Converts a v21 exploration dict into a v22 exploration dict.
Moves the labelled_as_correct field from the answer group level to the
outcome level, and adds two extra customization args to the
Expand All @@ -2648,7 +2648,7 @@ def _convert_v21_dict_to_v22_dict(cls, exploration_dict):

@classmethod
def _convert_v22_dict_to_v23_dict(cls, exploration_dict):
""" Converts a v22 exploration dict into a v23 exploration dict.
"""Converts a v22 exploration dict into a v23 exploration dict.
Adds a new customization arg to FractionInput interactions
which allows you to add custom placeholders.
Expand All @@ -2663,7 +2663,7 @@ def _convert_v22_dict_to_v23_dict(cls, exploration_dict):

@classmethod
def _convert_v23_dict_to_v24_dict(cls, exploration_dict):
""" Converts a v23 exploration dict into a v24 exploration dict.
"""Converts a v23 exploration dict into a v24 exploration dict.
Adds training_data parameter to each answer group to store training
data of corresponding answer group.
Expand All @@ -2678,7 +2678,7 @@ def _convert_v23_dict_to_v24_dict(cls, exploration_dict):

@classmethod
def _convert_v24_dict_to_v25_dict(cls, exploration_dict):
""" Converts a v24 exploration dict into a v25 exploration dict.
"""Converts a v24 exploration dict into a v25 exploration dict.
Adds additional tagged_misconception_id and
missing_prerequisite_skill_id fields to answer groups and outcomes
Expand All @@ -2694,7 +2694,7 @@ def _convert_v24_dict_to_v25_dict(cls, exploration_dict):

@classmethod
def _convert_v25_dict_to_v26_dict(cls, exploration_dict):
""" Converts a v25 exploration dict into a v26 exploration dict.
"""Converts a v25 exploration dict into a v26 exploration dict.
Move audio_translations into a seperate dict.
"""
Expand Down
2 changes: 1 addition & 1 deletion core/domain/exp_services_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,7 @@ def setUp(self):
}

def test_add_state_cmd(self):
""" Test adding of states."""
"""Test adding of states."""
exploration = exp_services.get_exploration_by_id(self.EXP_ID)

self.assertNotIn('new state', exploration.states)
Expand Down
2 changes: 1 addition & 1 deletion core/domain/fs_domain_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def test_listdir(self):


class GcsFileSystemUnitTests(test_utils.GenericTestBase):
""" Tests for the GCS file system."""
"""Tests for the GCS file system."""

def setUp(self):
super(GcsFileSystemUnitTests, self).setUp()
Expand Down
2 changes: 1 addition & 1 deletion core/domain/html_validation_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


class ContentMigrationTests(test_utils.GenericTestBase):
""" Tests the function associated with the migration of html
"""Tests the function associated with the migration of html
strings to valid RTE format.
"""

Expand Down
2 changes: 1 addition & 1 deletion core/domain/user_jobs_continuous_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ def _get_continuous_computation_class(cls):


class UserStatsAggregatorTest(test_utils.GenericTestBase):
""" Tests the calculation of a user's statistics -
"""Tests the calculation of a user's statistics -
impact score, average ratings, total plays
from the continuous computation of UserStatsAggregator.
"""
Expand Down
20 changes: 18 additions & 2 deletions scripts/pre_commit_linter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,8 @@ def _check_docstrings(all_files):
previous_line_message = (
'There should not be any empty lines before the end of '
'the multi-line docstring.')
space_after_triple_quotes_in_docstring_message = (
'There should be no space after """ in docstring.')
failed = False
is_docstring = False
is_class_or_function = False
Expand All @@ -1183,6 +1185,16 @@ def _check_docstrings(all_files):
is_docstring = True
is_class_or_function = False

# Check for space after """ in docstring.
if re.match(r'^""".+$', line) and is_docstring and (
line[3] == ' '):
failed = True
print '%s --> Line %s: %s' % (
filename, line_num + 1,
space_after_triple_quotes_in_docstring_message)
print ''
is_docstring = False

# Check if single line docstring span two lines.
if line == '"""' and prev_line.startswith('"""') and (
is_docstring):
Expand Down Expand Up @@ -1238,13 +1250,13 @@ def _check_docstrings(all_files):

is_docstring = False

# Check that the args in the docstring are listed in the same
# order as they appear in the function definition.
docstring_checker = docstrings_checker.ASTDocStringChecker()
for filename in files_to_check:
ast_file = ast.walk(ast.parse(FileCache.read(filename)))
func_defs = [n for n in ast_file if isinstance(n, ast.FunctionDef)]
for func in func_defs:
# Check that the args in the docstring are listed in the same
# order as they appear in the function definition.
func_result = docstring_checker.check_docstrings_arg_order(func)
for error_line in func_result:
print '%s --> Func %s: %s' % (
Expand Down Expand Up @@ -1530,6 +1542,7 @@ class CustomHTMLParser(HTMLParser.HTMLParser):
"""Custom HTML parser to check indentation."""

def __init__(self, filename, file_lines, debug, failed=False):
"""Define various variables to parse HTML."""
HTMLParser.HTMLParser.__init__(self)
self.tag_stack = []
self.debug = debug
Expand All @@ -1544,6 +1557,7 @@ def __init__(self, filename, file_lines, debug, failed=False):
'param', 'source', 'track', 'wbr']

def handle_starttag(self, tag, attrs):
"""Handle start tag of a HTML line."""
line_number, column_number = self.getpos()
# Check the indentation of the tag.
expected_indentation = self.indentation_level * self.indentation_width
Expand Down Expand Up @@ -1622,6 +1636,7 @@ def handle_starttag(self, tag, attrs):
self.failed = True

def handle_endtag(self, tag):
"""Handle end tag of a HTML line."""
line_number, _ = self.getpos()
tag_line = self.file_lines[line_number - 1]
leading_spaces_count = len(tag_line) - len(tag_line.lstrip())
Expand Down Expand Up @@ -1655,6 +1670,7 @@ def handle_endtag(self, tag):
print self.tag_stack

def handle_data(self, data):
"""Handle indentation level."""
data_lines = data.split('\n')
opening_block = tuple(['{% block', '{% macro', '{% if'])
ending_block = tuple(['{% end', '{%- end'])
Expand Down
2 changes: 1 addition & 1 deletion scripts/release_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _check_versions(current_release):


def _git_diff_names_only(left, right='HEAD'):
""" Get names of changed files from git.
"""Get names of changed files from git.
Args:
left: str. Lefthand timepoint.
Expand Down

0 comments on commit 0d676f9

Please sign in to comment.