Skip to content

Bugs in filters_test.py #199

@WindQAQ

Description

@WindQAQ

In image/filters_test.py, there are some buggy test cases:

  1. There are some patterns like
    with self.assertRaisesRegexp(TypeError,
    'Size of the filter must be Integers'):
    median_filter2d(tf_img, (3.5, 3))
    median_filter2d(tf_img, (None, 3))

    However, this is not safe because each context manager will catch only one exception, and then exit. That it, the following code snippet will pass the test:
def foo(x):
    if x < 5:
        raise ValueError("fail " + str(x))


class Test(tf.test.TestCase):

    def test_context_manager(self):
        with self.assertRaisesRegexp(ValueError, "fail 3"):
            foo(3)
            foo(2)
            foo(1)

        with self.assertRaises(ValueError):
            foo(5)
            foo(4)
            foo(3)
  1. One test case disables eager execution, but this will affect all test cases (in the same file) executed after it.
    def test_dimension(self):
    tf.compat.v1.disable_eager_execution()
    tf_img = tf.compat.v1.placeholder(tf.int32, shape=[3, 4, None])
    tf_img1 = tf.compat.v1.placeholder(tf.int32, shape=[3, None, 4])
    tf_img2 = tf.compat.v1.placeholder(tf.int32, shape=[None, 3, 4])

    In other words, test_check_eager will fail in this toy test case.
class Test(tf.test.TestCase):

    # Make it execute first
    def test_a(self):
        tf.compat.v1.disable_eager_execution()
        tf.compat.v1.placeholder(tf.float32, shape=(1, 2, None))

    def test_check_eager(self):
        if not tf.executing_eagerly():
            raise Exception("Not in eager mode")

This might not be what we want. In order to utilize tf.compat.v1.placeholder, which can be used to test None shape, in tf2.0, maybe @run_deprecated_v1 is helpful enough.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions