Skip to content

Commit

Permalink
add unit test for tqdm verbosity
Browse files Browse the repository at this point in the history
  • Loading branch information
frances-h committed Oct 24, 2023
1 parent 0141fec commit 4b07410
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/unit/synthesizer/test_tvae.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""TVAE unit testing module."""

from unittest.mock import MagicMock, call, patch

import pandas as pd

from ctgan.synthesizers import TVAE


class TestTVAE:

@patch('ctgan.synthesizers.tvae.tqdm')
def test_fit_verbose(self, tqdm_mock):
"""Test verbose parameter prints progress bar."""
# Setup
epochs = 10

def mock_iter():
for i in range(epochs):
yield i

iterator_mock = MagicMock()
iterator_mock.__iter__.side_effect = mock_iter
tqdm_mock.return_value = iterator_mock
synth = TVAE(epochs=epochs, verbose=True)
train_data = pd.DataFrame({
'col1': [0, 1, 2, 3, 4],
'col2': [10, 11, 12, 13, 14]
})

# Run
synth.fit(train_data)

# Assert
tqdm_mock.assert_called_once_with(range(10), disable=False)
iterator_mock.set_description.call_args_list[0] == call('Loss: 0.000')
assert iterator_mock.set_description.call_count == 11

0 comments on commit 4b07410

Please sign in to comment.