Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix part of #6550: Write tests for extensions/ and utils #7113

Merged
merged 9 commits into from
Jul 17, 2019

Conversation

lilithxxx
Copy link
Contributor

@lilithxxx lilithxxx commented Jul 8, 2019

Explanation

Fixes part of #6550: Write tests for extensions/ and utils

Checklist

  • The PR title starts with "Fix #bugnum: ", followed by a short, clear summary of the changes. (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
  • The PR explanation includes the words "Fixes #bugnum: ..." (or "Fixes part of #bugnum" if the PR only partially fixes an issue).
  • The linter/Karma presubmit checks have passed.
    • These should run automatically, but if not, you can manually trigger them locally using python scripts/pre_commit_linter.py and bash scripts/run_frontend_tests.sh.
  • The PR is made from a branch that's not called "develop".
  • The PR has an appropriate "CHANGELOG: ..." label (If you are unsure of which label to add, ask the reviewers for guidance).
  • The PR follows the style guide.
  • The PR addresses the points mentioned in the codeowner checks for the files/folders changed. (See the codeowner's wiki page.)
  • The PR is assigned to an appropriate reviewer.
    • If you're a new contributor, please ask on Gitter for someone to assign a reviewer and don't tick this checkbox.
    • If you're not sure who the appropriate reviewer is, please assign to the issue's "owner" -- see the "talk-to" label on the issue. Do not only request the review but also add the reviewer as an assignee.

@@ -74,9 +83,6 @@ def _create_state_answers_dict(

def _get_calculation_instance(self):
"""Requires the existance of the class constant: CALCULATION_ID."""
if not hasattr(self, 'CALCULATION_ID'):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines are in the test file and are untested.

@@ -211,18 +211,6 @@ def html_body(self):
feconf.INTERACTIONS_DIR, self.id, '%s.html' % self.id))
return html_templates

@property
def validator_html(self):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is not used anywhere

@@ -48,11 +48,6 @@
('show_generic_submit_button', bool)]


def mock_get_filename_with_dimensions(filename, unused_exp_id):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function and its use in this test file is not needed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means the behavior changed at some point but we didn't update the tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea that's correct

@@ -38,14 +38,7 @@ def check_validation(self, rte_component_class, valid_items, invalid_items):
a TypeError when validated.
"""
for item in valid_items:
try:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines are in the test file and are untested.

schema_utils_test.py Show resolved Hide resolved
@@ -116,21 +114,20 @@ def get_exploration_components_from_dir(dir_path):
for filename in files:
filepath = os.path.join(root, filename)
if root == dir_path:
if filepath.endswith('.DS_Store'):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the structure of the code as I don't know if it will be a good idea to create a .DS_Store file just to test this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is fine.

@@ -144,50 +141,6 @@ def get_exploration_components_from_dir(dir_path):
return yaml_content, assets_list


def get_exploration_components_from_zip(zip_file_contents):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is not used

Copy link
Contributor

@nithusha21 nithusha21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good... Just some minor comments.

re.escape(
'For visualization BarChart, expected option names '
'[\'x_axis_label\', \'y_axis_label\']; received names []')):
self.assertEqual(bar_chart_instance.validate(), 12)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why object.validate() returns a value....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was a mistake. Fixed it!

@@ -30,6 +30,15 @@ def test_requires_override_for_calculation(self):
answer_models.BaseCalculation().calculate_from_state_answers_dict(
state_answers_dict={})

def test_equality_of_hashable_answers(self):
hashable_answer_1 = answer_models._HashableAnswer('answer_1') # pylint: disable=protected-access
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I thought the plan was to test protected functions using public interfaces.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to test the equality of hashable_answers with the eq method. This is why, an exception needs to be made here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the __eq__ method is what is actually used to implement "a == b" in Python, so you should be able to use the latter below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

hashable_answer_3 = answer_models._HashableAnswer('answer_1') # pylint: disable=protected-access

self.assertFalse(hashable_answer_1.__eq__(hashable_answer_2))
self.assertTrue(hashable_answer_1.__eq__(hashable_answer_3))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

== doesn't work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Explained above

@@ -48,11 +48,6 @@
('show_generic_submit_button', bool)]


def mock_get_filename_with_dimensions(filename, unused_exp_id):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means the behavior changed at some point but we didn't update the tests?

@@ -116,21 +114,20 @@ def get_exploration_components_from_dir(dir_path):
for filename in files:
filepath = os.path.join(root, filename)
if root == dir_path:
if filepath.endswith('.DS_Store'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this change is fine.

utils_test.py Outdated
utils.require_valid_name(name, 'name_type')

name = 0
with self.assertRaisesRegexp(Exception, 'name_type must be a string.'):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error message seems wrong? name_type is a string right? name is not a string.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! The exception message in utils.py was wrong. It was '%s must be a string.' % name_type whereas it should have been '%s must be a string.' % name because we are validating name

@lilithxxx
Copy link
Contributor Author

@nithusha21 PTAL!

Copy link
Contributor

@nithusha21 nithusha21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks!

Copy link
Contributor

@vojtechjelinek vojtechjelinek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from code owner's perspective. Thanks!

Copy link
Contributor

@kevinlee12 kevinlee12 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

Copy link
Contributor

@apb7 apb7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from code owner's perspective, thanks!

@apb7 apb7 removed their assignment Jul 14, 2019
@oppiabot
Copy link

oppiabot bot commented Jul 14, 2019

Hi @lilithxxx. Due to recent changes in the "develop" branch, this PR now has a merge conflict. Please follow this link if you need help resolving the conflict, so that the PR can be merged. Thanks!

@@ -30,6 +30,15 @@ def test_requires_override_for_calculation(self):
answer_models.BaseCalculation().calculate_from_state_answers_dict(
state_answers_dict={})

def test_equality_of_hashable_answers(self):
hashable_answer_1 = answer_models._HashableAnswer('answer_1') # pylint: disable=protected-access
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the __eq__ method is what is actually used to implement "a == b" in Python, so you should be able to use the latter below.

from core.domain import interaction_registry
from core.domain import obj_services
from core.tests import test_utils
from extensions.interactions import base
from extensions.interactions.CodeRepl import CodeRepl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't do this, use interaction_registry to retrieve the interaction class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -27,7 +27,7 @@ def test_copier(self):
generator = generators.Copier()
self.assertEqual(generator.generate_value({}, **{'value': 'a'}), 'a')
self.assertEqual(generator.generate_value(
{}, **{'value': 'a', 'parse_with_jinja': False}), 'a')
None, **{'value': 'a', 'parse_with_jinja': False}), 'a')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am sorry about this one, shouldn't have modified the existing test. I kept the old one and added a new one.

@seanlip seanlip removed their assignment Jul 15, 2019
@aks681 aks681 removed their assignment Jul 15, 2019
@seanlip seanlip assigned lilithxxx and unassigned brianrodri Jul 16, 2019
@lilithxxx
Copy link
Contributor Author

@seanlip @DubeySandeep PTAL!

@lilithxxx lilithxxx assigned seanlip and unassigned lilithxxx Jul 16, 2019
@brianrodri brianrodri merged commit 243e374 into oppia:develop Jul 17, 2019
@lilithxxx lilithxxx deleted the extensions_test branch July 17, 2019 04:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants