예제 #1
0
 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()
예제 #2
0
 def testError(self):
     tests = [
         ('', -1, False),
         ('', 0, False)
     ]
     for test in tests:
         with self.assertRaises(ValueError), outfiles(*test):
             pass
예제 #3
0
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()
예제 #4
0
 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)
예제 #5
0
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
예제 #6
0
def test_outfiles_error(test):
    with pytest.raises(ValueError), outfiles(*test):
        pass