Skip to content

Commit

Permalink
Fix warnings in test_visualizer.py (#1039)
Browse files Browse the repository at this point in the history
 - Ticket no. 112846
 - Close plt.Figure each time the test teardowns
 - Replace deprecated function usage: np.random.random_integers() ->
   np.random.randint()

Signed-off-by: Kim, Vinnam <[email protected]>
  • Loading branch information
vinnamkim authored Jun 12, 2023
1 parent a702d61 commit 313446d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
(<https://github.com/openvinotoolkit/datumaro/pull/1036>)

### Bug fixes
- Fix warnings in test_visualizer.py
(<https://github.com/openvinotoolkit/datumaro/pull/1039>)

## 26/05/2023 - Release 1.3.1
### Bug fixes
Expand Down
37 changes: 24 additions & 13 deletions tests/unit/test_visualizer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Copyright (C) 2022-2023 Intel Corporation
#
# SPDX-License-Identifier: MIT

from dataclasses import dataclass
from unittest import TestCase, mock

import matplotlib.pyplot as plt
import numpy as np
from matplotlib.figure import Figure

Expand Down Expand Up @@ -123,7 +128,13 @@ def _check(infer_grid_size, expected_grid_size):
_check(test_case.infer_grid_size, test_case.expected_grid_size)


class LabelVisualizerTest(TestCase, VisualizerTestBase):
class TestCaseClosePltFigure(TestCase):
def tearDown(self) -> None:
plt.close("all")
return super().tearDown()


class LabelVisualizerTest(TestCaseClosePltFigure, VisualizerTestBase):
@classmethod
def setUpClass(cls):
cls.subset = "train"
Expand Down Expand Up @@ -155,7 +166,7 @@ def test_vis_gallery(self):
self._test_vis_gallery(self.DEFAULT_GRID_SIZE_TEST_CASES)


class PointsVisualizerTest(TestCase, VisualizerTestBase):
class PointsVisualizerTest(TestCaseClosePltFigure, VisualizerTestBase):
@classmethod
def setUpClass(cls):
cls.subset = "train"
Expand All @@ -166,7 +177,7 @@ def setUpClass(cls):
media=Image.from_numpy(data=np.ones((4, 6, 3))),
annotations=[
Points(
np.random.random_integers(0, 6, size=10 * 2),
np.random.randint(0, 6, size=10 * 2),
label=label_idx,
id=img_idx * img_idx + label_idx,
group=1,
Expand All @@ -189,7 +200,7 @@ def test_vis_gallery(self):
self._test_vis_gallery(self.DEFAULT_GRID_SIZE_TEST_CASES)


class MaskVisualizerTest(TestCase, VisualizerTestBase):
class MaskVisualizerTest(TestCaseClosePltFigure, VisualizerTestBase):
@classmethod
def setUpClass(cls):
cls.subset = "train"
Expand Down Expand Up @@ -223,7 +234,7 @@ def test_vis_gallery(self):
self._test_vis_gallery(self.DEFAULT_GRID_SIZE_TEST_CASES)


class PolygonVisualizerTest(TestCase, VisualizerTestBase):
class PolygonVisualizerTest(TestCaseClosePltFigure, VisualizerTestBase):
@classmethod
def setUpClass(cls):
cls.subset = "train"
Expand All @@ -234,7 +245,7 @@ def setUpClass(cls):
media=Image.from_numpy(data=np.ones((4, 6, 3))),
annotations=[
Polygon(
np.random.random_integers(0, 6, size=10 * 2),
np.random.randint(0, 6, size=10 * 2),
label=label_idx,
id=img_idx * img_idx + label_idx,
group=1,
Expand All @@ -257,7 +268,7 @@ def test_vis_gallery(self):
self._test_vis_gallery(self.DEFAULT_GRID_SIZE_TEST_CASES)


class PolyLineVisualizerTest(TestCase, VisualizerTestBase):
class PolyLineVisualizerTest(TestCaseClosePltFigure, VisualizerTestBase):
@classmethod
def setUpClass(cls):
cls.subset = "train"
Expand All @@ -268,7 +279,7 @@ def setUpClass(cls):
media=Image.from_numpy(data=np.ones((4, 6, 3))),
annotations=[
PolyLine(
np.random.random_integers(0, 6, size=10 * 2),
np.random.randint(0, 6, size=10 * 2),
label=label_idx,
id=img_idx * img_idx + label_idx,
group=1,
Expand All @@ -291,7 +302,7 @@ def test_vis_gallery(self):
self._test_vis_gallery(self.DEFAULT_GRID_SIZE_TEST_CASES)


class BboxVisualizerTest(TestCase, VisualizerTestBase):
class BboxVisualizerTest(TestCaseClosePltFigure, VisualizerTestBase):
@classmethod
def setUpClass(cls):
cls.subset = "train"
Expand Down Expand Up @@ -328,7 +339,7 @@ def test_vis_gallery(self):
self._test_vis_gallery(self.DEFAULT_GRID_SIZE_TEST_CASES)


class CaptionVisualizerTest(TestCase, VisualizerTestBase):
class CaptionVisualizerTest(TestCaseClosePltFigure, VisualizerTestBase):
@classmethod
def setUpClass(cls):
cls.subset = "train"
Expand Down Expand Up @@ -359,7 +370,7 @@ def test_vis_gallery(self):
self._test_vis_gallery(self.DEFAULT_GRID_SIZE_TEST_CASES)


class SuperResolutionVisualizerTest(TestCase, VisualizerTestBase):
class SuperResolutionVisualizerTest(TestCaseClosePltFigure, VisualizerTestBase):
@classmethod
def setUpClass(cls):
cls.subset = "train"
Expand Down Expand Up @@ -389,7 +400,7 @@ def test_vis_gallery(self):
self._test_vis_gallery(self.DEFAULT_GRID_SIZE_TEST_CASES)


class DepthVisualizerTest(TestCase, VisualizerTestBase):
class DepthVisualizerTest(TestCaseClosePltFigure, VisualizerTestBase):
@classmethod
def setUpClass(cls):
cls.subset = "train"
Expand Down Expand Up @@ -419,7 +430,7 @@ def test_vis_gallery(self):
self._test_vis_gallery(self.DEFAULT_GRID_SIZE_TEST_CASES)


class EllipseVisualizerTest(TestCase, VisualizerTestBase):
class EllipseVisualizerTest(TestCaseClosePltFigure, VisualizerTestBase):
@classmethod
def setUpClass(cls):
cls.subset = "train"
Expand Down

0 comments on commit 313446d

Please sign in to comment.