def test_file_info_for_temp_file(self): with tempfile.NamedTemporaryFile('w') as tmp: tmp.write('foobar') tmp.flush() f = open(tmp.name) self.assertEqual(frogress.get_file_info(f), { 'filename': tmp.name, 'size': 6, 'step_callback': f.tell, })
def test_file_info(self, getsize): getsize.return_value = 123 # DummyObject is used here as Mock would always answer True for hasattr f = DummyObject() f.name = '/foobar.gz' f.tell = 'step-callback' f.seek = '' f.fileno = 1 self.assertEqual(frogress.get_file_info(f), { 'filename': '/foobar.gz', 'size': 123, 'step_callback': 'step-callback', })
def test_file_info_for_non_files(self): self.assertIsNone(frogress.get_file_info([]))