def test_finished_state(self): worker = Worker() worker.configure(destination=self.image_net_home, number_of_images=5, images_per_category=10) change_spy = QSignalSpy(worker.stateChanged) worker.start_download() while not worker.complete: received = change_spy.wait(500) worker = Worker() self.assertEqual(worker.download_state, 'finished') self.assertTrue(worker.complete) worker = Worker() expected_path = os.path.abspath(self.image_net_home) state_data = json.loads(worker.state_data_json) self.assertEqual(state_data['downloadPath'], expected_path) self.assertEqual(state_data['numberOfImages'], 5) self.assertEqual(state_data['imagesPerCategory'], 10) self.assertEqual(state_data['timeLeft'], '0 seconds') self.assertEqual(state_data['imagesLoaded'], 5) self.assertEqual(state_data['failures'], 0) self.assertEqual(state_data['failedUrls'], []) self.assertEqual(state_data['progress'], 1.0)
def test_wait_until_download_complete(self): worker = Worker() worker.configure(destination=self.image_net_home, number_of_images=10, images_per_category=5) change_spy = QSignalSpy(worker.stateChanged) worker.start_download() while not worker.complete: received = change_spy.wait(500) self.assertEqual(worker.download_state, 'finished') self.assertTrue(worker.complete)