示例#1
0
    def setUp(self):
        print('\n-------------------------')
        print('Running: %s\n' % self.id())

        # The response library cannot replay requests in a multi-threaded
        # environment. We have to disable threading for testing...
        with open(CONFIG_FILE) as f:
            self._config = json.load(f)
        self._config.update({
            'folder_threads': 1,
            'file_threads': 1,
            'upload_threads': 1,
        })

        cache_folder = self._get_cache_base_folder()
        if bool(os.environ.get('RESET_CACHE')):
            shutil.rmtree(cache_folder, ignore_errors=True)

        self._io = expect.ExpectedInputOutput()
        self._io.set_transform_fn(format_path)
        sys.stdin = self._io
        sys.stdout = self._io

        self._api_url_re = re.compile(
            r'https://api\.smugmug\.com/api/v2[\!/](?P<path>.*)')
        self._upload_url_re = re.compile(
            r'https://(?P<path>upload)\.smugmug\.com/')
        self._path_replace_re = re.compile(r'[!/?]')

        self._command_index = 0
        self._pending = set()
        self._replay_cached_requests = os.path.exists(cache_folder)

        self._do('rm -r -f {root}')
        shutil.rmtree(ROOT_DIR, ignore_errors=True)
示例#2
0
    def testException(self):
        mock_io = expect.ExpectedInputOutput()
        sys.stdout = mock_io

        def will_raise():
            raise Exception(u'Unicode: \xe2')

        with thread_pool.ThreadPool(2) as pool:
            pool.add(will_raise)

        mock_io.assert_output_was(u'Unicode: \xe2')
示例#3
0
    def test_update_progress(self):
        io = expect.ExpectedInputOutput()
        sys.stdout = io
        with freezegun.freeze_time('2019-01-01 12:00:00') as frozen_time:
            with task_manager.TaskManager() as manager:
                with manager.start_task(0, 'Some task'):
                    frozen_time.tick(delta=datetime.timedelta(milliseconds=1))
                    manager.update_progress(0, 'Some task', ': 25%')
                    frozen_time.tick(delta=datetime.timedelta(
                        milliseconds=100))
                    manager.update_progress(0, 'Some task', ': 50%')
                    frozen_time.tick(delta=datetime.timedelta(milliseconds=1))
                    manager.update_progress(0, 'Some task', ': 75%')

        io.assert_output_was(
            self.except_status(['Some task', 'Some task: 50%']))
    def testWrite(self):
        mock_io = expect.ExpectedInputOutput()
        sys.stdout = mock_io

        thread1_turn = queue.Queue()
        thread2_turn = queue.Queue()
        thread1_turn.put(True)
        with thread_safe_print.ThreadSafePrint():
            with thread_pool.ThreadPool(2) as pool:
                pool.add(self._thread1, thread1_turn, thread2_turn)
                pool.add(self._thread2, thread1_turn, thread2_turn)

        mock_io.assert_output_was([
            'Thread 1 starts, thread 1 finishes.',
            'Thread 2 starts, thread 2 finishes.'
        ])
示例#5
0
 def setUp(self):
     self._io = expect.ExpectedInputOutput()
     sys.stdin = self._io
     sys.stdout = self._io