示例#1
0
 def test_reset_state(self, *, store):
     with patch('shutil.rmtree') as rmtree:
         store.reset_state()
         rmtree.assert_called_once_with(store.path.absolute())
示例#2
0
 def test_table(self, *, command):
     with patch('faust.utils.terminal.table') as table:
         data = [['A', 'B', 'C']]
         t = command.table(data, title='foo')
         assert t is table.return_value
         table.assert_called_once_with(data, title='foo', target=sys.stdout)
示例#3
0
 def test_app_from_str(self, *, command):
     with patch('faust.cli.base.find_app') as find_app:
         res = command._app_from_str('foo')
         assert res is find_app.return_value
         find_app.assert_called_once_with('foo')
示例#4
0
 def test_discover__unknown_module(self, *, app):
     app.conf.autodiscover = ['xcxz']
     app.conf.origin = 'faust'
     with patch('faust.app.base.venusian'):
         with pytest.raises(ModuleNotFoundError):
             app.discover()
示例#5
0
 def test_send_changelog__no_current_event(self, *, table):
     with patch('faust.tables.base.current_event') as current_event:
         current_event.return_value = None
         with pytest.raises(RuntimeError):
             table._send_changelog('k', 'v')
示例#6
0
 def test__new_lock(self, d):
     d.thread_safety = True
     with patch('threading.RLock') as RLock:
         res = d._new_lock()
         assert res is RLock.return_value
示例#7
0
 def test_relative_event__raises_if_no_event(self, *, table):
     with patch('faust.tables.base.current_event') as current_event:
         current_event.return_value = None
         with pytest.raises(RuntimeError):
             table._relative_event(None)
示例#8
0
 def test_on_siginit__no_spinner(self, worker):
     worker.spinner = None
     with patch('asyncio.ensure_future') as ensure_future:
         worker._on_sigint()
         coro = ensure_future.call_args[0][0]
     asyncio.ensure_future(coro).cancel()
示例#9
0
 def test_on_crash(self, *, thread):
     with patch('traceback.print_exc') as print_exc:
         thread.on_crash('foo {0!r}', 10)
         print_exc.assert_called_once_with(None, ANY)
示例#10
0
 def test_change_workdir__already_cwd(self, worker):
     with patch('os.chdir') as chdir:
         p = Path.cwd()
         worker.change_workdir(p)
         chdir.assert_not_called()
示例#11
0
 def test_setproctitle(self, worker, app):
     with patch('faust.worker.setproctitle') as setproctitle:
         worker._setproctitle('foo')
         setproctitle.assert_called_with(
             f'[Faust:Worker] -foo- testid -p {app.conf.web_port} '
             f'{app.conf.datadir.absolute()}')
示例#12
0
 def test_change_workdir(self, worker):
     with patch('os.chdir') as chdir:
         p = Path('baz')
         worker.change_workdir(p)
         chdir.assert_called_once_with(p.absolute())
示例#13
0
 def no_rocks(self):
     with patch('faust.stores.rocksdb.rocksdb', None) as rocks:
         yield rocks
示例#14
0
 def rocks(self):
     with patch('faust.stores.rocksdb.rocksdb') as rocks:
         yield rocks
示例#15
0
 async def test_wait_for_subscriptions__notset(self, *, con):
     with patch("asyncio.Future") as Future:
         Future.return_value = done_future()
         await con.wait_for_subscriptions()
示例#16
0
 def test_get_timestamp__event_is_None(self, *, event, wtable):
     wtable.get_relative_timestamp = None
     with patch("faust.tables.wrappers.current_event") as ce:
         ce.return_value = None
         with pytest.raises(RuntimeError):
             assert wtable.get_timestamp(None)
示例#17
0
 async def test_wait_for_subscriptions(self, *, con):
     with patch("asyncio.Future", AsyncMock()) as Future:
         con._subscription_done = None
         await con.wait_for_subscriptions()
         Future.assert_called_once_with(loop=con.loop)
示例#18
0
def current_event(*, freeze_time):
    with patch("faust.tables.wrappers.current_event") as current_event:
        with patch("faust.tables.base.current_event", current_event):
            current_event.return_value.message.timestamp = freeze_time.time
            yield current_event
示例#19
0
 def test_relative_now__no_event(self, *, table):
     with patch('faust.tables.base.current_event') as ce:
         ce.return_value = None
         with patch('time.time') as time:
             assert table._relative_now(None) is time()
示例#20
0
 def test_windowed_now(self, *, table):
     with patch('faust.tables.base.current_event'):
         table._windowed_timestamp = Mock(name='windowed_timestamp')
         ret = table._windowed_now('k')
         table._windowed_timestamp.assert_called_once_with('k', 0)
         assert ret is table._windowed_timestamp()
示例#21
0
 async def test_debug_enabled_warns_on_start(self, *, app):
     with patch('faust.app.base.logger') as logger:
         await app.on_start()
         logger.warning.assert_called_once()
示例#22
0
 def test_new_scanner(self, *, app):
     with patch('faust.app.base.venusian') as venusian:
         pat = re.compile('^foo')
         scanner = app._new_scanner(pat)
         venusian.Scanner.assert_called_with(ignore=[pat.search])
         assert scanner is venusian.Scanner()
示例#23
0
 async def test__wait_for_futures__CancelledError(self, *, service):
     service._futures = [Mock()]
     with patch('asyncio.shield', AsyncMock()) as shield:
         with patch('asyncio.wait', AsyncMock()):
             shield.coro.side_effect = asyncio.CancelledError()
             await service._wait_for_futures()
示例#24
0
文件: test_base.py 项目: euwen/faust
 def test_import_relative_to_app(self, *, command, ctx):
     with patch('faust.cli.base.symbol_by_name') as symbol_by_name:
         res = command.import_relative_to_app('foo')
         assert res is symbol_by_name.return_value
         symbol_by_name.assert_called_once_with('foo')
示例#25
0
def test__prepare_cli():
    ctx = Mock(name='context')
    state = ctx.ensure_object.return_value = Mock(name='state')
    root = ctx.find_root.return_value = Mock(name='root')
    root.side_effects = False
    app = Mock(name='app')
    try:
        _prepare_cli(
            ctx,
            app=app,
            quiet=False,
            debug=True,
            workdir='/foo',
            datadir='/data',
            json=True,
            no_color=False,
            loop='foo',
        )

        assert state.app is app
        assert not state.quiet
        assert state.debug
        assert state.workdir == '/foo'
        assert state.datadir == '/data'
        assert state.json
        assert not state.no_color
        assert state.loop == 'foo'

        root.side_effects = True
        with patch('os.chdir') as chdir:
            with patch('faust.cli.base.enable_all_colors') as eac:
                with patch('faust.utils.terminal.isatty') as isatty:
                    with patch('faust.cli.base.disable_all_colors') as dac:
                        isatty.return_value = True
                        _prepare_cli(
                            ctx,
                            app=app,
                            quiet=False,
                            debug=True,
                            workdir='/foo',
                            datadir='/data',
                            json=False,
                            no_color=False,
                            loop='foo',
                        )
                        chdir.assert_called_with(Path('/foo').absolute())
                        eac.assert_called_once_with()
                        dac.assert_not_called()
                        _prepare_cli(
                            ctx,
                            app=app,
                            quiet=False,
                            debug=True,
                            workdir='/foo',
                            datadir='/data',
                            json=True,
                            no_color=False,
                            loop='foo',
                        )
                        dac.assert_called_once_with()
                        dac.reset_mock()
                        eac.reset_mock()
                        _prepare_cli(
                            ctx,
                            app=app,
                            quiet=False,
                            debug=True,
                            workdir='/foo',
                            datadir='/data',
                            json=False,
                            no_color=True,
                            loop='foo',
                        )
                        eac.assert_not_called()
                        dac.assert_called_once_with()
                        _prepare_cli(
                            ctx,
                            app=app,
                            quiet=False,
                            debug=True,
                            workdir=None,
                            datadir=None,
                            json=False,
                            no_color=True,
                            loop='foo',
                        )
    finally:
        os.environ.pop('F_DATADIR', None)
        os.environ.pop('F_WORKDIR', None)
示例#26
0
 def test_traced_from_parent_span(self, *, cthread):
     with patch(TESTED_MODULE + '.traced_from_parent_span') as traced:
         parent_span = Mock(name='parent_span')
         ret = cthread.traced_from_parent_span(parent_span, foo=303)
         traced.assert_called_once_with(parent_span, callback=None, foo=303)
         assert ret is traced.return_value
示例#27
0
 def test_dumps(self, *, command):
     with patch('faust.utils.json.dumps') as dumps:
         obj = Mock(name='obj')
         assert command.dumps(obj) is dumps.return_value
         dumps.assert_called_once_with(obj)
示例#28
0
 def test_set_key(self, *, table):
     with patch('faust.tables.table.current_event'):
         table._send_changelog = Mock(name='_send_changelog')
         table._set_key('foo', 'val')
         table._send_changelog.asssert_called_once_with('foo', 'val')
         assert table['foo'] == 'val'
示例#29
0
 def test_finalize_concrete_app(self, *, command, app):
     with patch('sys.argv', []):
         command._finalize_concrete_app(app)
示例#30
0
 async def test_open_db_for_partition(self, *, store, db_for_partition):
     with patch('faust.stores.rocksdb.rocksdb.errors.RocksIOError',
                KeyError):
         assert (await store._try_open_db_for_partition(3) is
                 db_for_partition.return_value)