Skip to content

Commit

Permalink
fix: test bug due to bad mocks (#878)
Browse files Browse the repository at this point in the history
  • Loading branch information
JGSweets authored Jun 15, 2023
1 parent 32dc772 commit 88f7111
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions dataprofiler/tests/labelers/test_character_level_cnn_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@
}


def mock_open(filename, *args):
def mock_open(filename, *args, **kwargs):
if filename.find("model_parameters") >= 0:
return StringIO(json.dumps(mock_model_parameters))
elif filename.find("label_mapping") >= 0:
return StringIO(json.dumps(mock_label_mapping))
return StringIO()


def setup_save_mock_open(mock_open):
Expand Down Expand Up @@ -391,10 +392,7 @@ def test_threshold_layer(self):
self.assertCountEqual(threshold_output, expected_threshold_output)

@mock.patch("tensorflow.keras.Model.save", return_value=None)
@mock.patch("tensorflow.keras.models.load_model", return_value=None)
@mock.patch(
"dataprofiler.labelers.character_level_cnn_model.callable", return_value=True
)
@mock.patch("tensorflow.keras.models.load_model", return_value=mock.Mock())
@mock.patch("builtins.open")
def test_save(self, mock_open, *mocks):
# setup mock
Expand Down Expand Up @@ -430,11 +428,8 @@ def test_save(self, mock_open, *mocks):
StringIO.close(mock_file)

@mock.patch("tensorflow.keras.Model.save", return_value=None)
@mock.patch("tensorflow.keras.models.load_model", return_value=None)
@mock.patch("tensorflow.keras.models.load_model", return_value=mock.Mock())
@mock.patch("builtins.open", side_effect=mock_open)
@mock.patch(
"dataprofiler.labelers.character_level_cnn_model.callable", return_value=True
)
def test_load(self, *mocks):
dir = os.path.join(_resource_labeler_dir, "unstructured_model/")
loaded_model = CharacterLevelCnnModel.load_from_disk(dir)
Expand Down

0 comments on commit 88f7111

Please sign in to comment.