-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Conversation
@@ -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'): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
@@ -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'): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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
There was a problem hiding this 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) |
There was a problem hiding this comment.
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....
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
== doesn't work?
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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'): |
There was a problem hiding this comment.
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.'): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
@nithusha21 PTAL! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM thanks!
There was a problem hiding this 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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
There was a problem hiding this 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!
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 |
There was a problem hiding this comment.
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.
extensions/interactions/base_test.py
Outdated
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 @DubeySandeep PTAL! |
Explanation
Fixes part of #6550: Write tests for extensions/ and utils
Checklist
python scripts/pre_commit_linter.py
andbash scripts/run_frontend_tests.sh
.