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

Add error message checking into existing python tests #3324

Merged
merged 2 commits into from
Sep 13, 2021

Conversation

stiepan
Copy link
Member

@stiepan stiepan commented Sep 8, 2021

Signed-off-by: Kamil Tokarski ktokarski@nvidia.com

Add check against expected messages to following python assert_raises/raises tests:
dali/test/python/test_operator_squeeze.py
dali/test/python/test_dali_tf_dataset_shape.py
dali/test/python/test_external_source_impl_utils.py
dali/test/python/test_external_source_parallel.py
dali/test/python/test_operator_crop_mirror_normalize.py
dali/test/python/test_external_source_impl.py
dali/test/python/test_operator_random_object_bbox.py

Description

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Refactoring (Redesign of existing code that doesn't affect functionality)
  • Other (e.g. Documentation, Tests, Configuration)

What happened in this PR

Additional information

  • Affected modules and functionalities:
  • Key points relevant for the review:

Checklist

Tests

  • Existing tests apply
  • New tests added
    • Python tests
    • GTests
    • Benchmark
    • Other
  • N/A

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: N/A

JIRA TASK: DALI-2234

Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>
with assert_raises(RuntimeError):
_test_err_args(classes=[0,1,2,3], weights=np.float32([1,2,3]))
with assert_raises(RuntimeError):
_test_err_args(classes=np.int32([0,1,2,3]), weights=[3,2,1])
Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed kwargs

weights -> class_weights
ignore_classes -> ignore_class

to meet api names, I believe that was intended check here.

@stiepan
Copy link
Member Author

stiepan commented Sep 8, 2021

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2939211]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2939211]: BUILD PASSED

Copy link
Contributor

@klecki klecki left a comment

Choose a reason for hiding this comment

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

Just some nitpicks.

Comment on lines 63 to 67
expected_error_msgs = (
common_msg.format("a callable that does not accept arguments"),
"External source callback must be a callable with 0 or 1 argument",
common_msg.format("an iterable"),
common_msg.format("a generator function"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason for using tuple instead of list of the expected error msgs?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not really, subconscious preference I guess.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

with assert_raises(RuntimeError):
pipe.build()
pipe.run()
expected_errors = (
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here about tuple vs list.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

yield raises(TypeError,
"`output_dtypes` should be provided as single tf.DType value or a tuple of tf.DType values")(
dali_pipe_deprecated), { "shapes": 2, }, 2, tf.uint8, dali_types.UINT8, 1, 2
Copy link
Contributor

Choose a reason for hiding this comment

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

If any fixes appear, pleas add the missing newline

Copy link
Member Author

Choose a reason for hiding this comment

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

done

{ "shapes": 2, "output_shapes": 2, "dtypes": tf.uint8 }, 2, tf.uint8, dali_types.UINT8, 1, 2
yield dali_pipe_deprecated_raises, \
error_msg = "Usage of `{}` is deprecated in favor of `output_{}`*only `output_{}` should be provided."
yield raises(ValueError, error_msg.format(*(("shapes",) * 3)))(dali_pipe_deprecated), \
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe

with assert_raises(ValueError, glob=error_msg.format(...)):
   ...

would be less of a parentheses rollecoaster?

Copy link
Member Author

Choose a reason for hiding this comment

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

added named variables for error message strings

Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>
@stiepan
Copy link
Member Author

stiepan commented Sep 13, 2021

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2969924]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [2969924]: BUILD PASSED

@stiepan stiepan merged commit 3a2c603 into NVIDIA:main Sep 13, 2021
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.

4 participants