def testProgress(self, tqdm): test = ('%d', 3, True) res = ['0', '1', '2'] with outfiles(*test) as pbar: self.assertTrue(tqdm.called) self.assertEqual(list(tqdm.call_args[0][0]), res) self.assertIsInstance(pbar, Mock) pbar.close.assert_called_with()
def testError(self): tests = [ ('', -1, False), ('', 0, False) ] for test in tests: with self.assertRaises(ValueError), outfiles(*test): pass
def test_outfiles_progress(mocker): tqdm = mocker.patch('markovchain.cli.util.tqdm') test = ('%d', 3, True) res = ['0', '1', '2'] with outfiles(*test) as pbar: assert tqdm.called assert list(tqdm.call_args[0][0]) == res assert isinstance(pbar, Mock) pbar.close.assert_called_once_with()
def testNoProgress(self, tqdm): tests = [ (('', 1, False), ['']), (('%d', 2, False), ['0', '1']) ] for test, res in tests: with outfiles(*test) as it: it = list(it) self.assertFalse(tqdm.called) self.assertEqual(it, res)
def test_outfiles(mocker, test, res): tqdm = mocker.patch('markovchain.cli.util.tqdm') with outfiles(*test) as files: files = list(files) assert not tqdm.called assert files == res
def test_outfiles_error(test): with pytest.raises(ValueError), outfiles(*test): pass