def add_spec(spec: str) -> Do: yield NS.lift(present_venv(name)) yield NS.lift(variable_set_prefixed('interpreter', '/usr/bin/python3.7')) yield NS.lift(variable_set_prefixed('debug_pythonpath', True)) yield request('cram', spec, name=name) data = yield NS.inspect(lambda a: a.data) return k(data.venvs).must(contain(name)) & k(data.active).must(contain(target))
def crm_rplugin_spec() -> Do: temp_dir('rplugin', 'venv', name, 'lib', 'python3.7') yield request('init') data = yield NS.inspect(lambda a: a.data) rplugin = data.chromatin_rplugin.to_either('no chromatin rplugin') venv = data.chromatin_venv.to_either('no chromatin venv') return ( k(rplugin).must(be_right(DistRplugin.cons('chromatin', 'chromatin'))) & k(venv).must(eq(rplugin / _.name)))
def read_conf(self) -> Expectation: rplugins = conf_data.map(Rplugin.from_config) successes = List( Right( DirRplugin.cons('null', '/dev/null', True, List('/some/path'))), Right(SiteRplugin.cons('plug', 'plug')), ) return ((k(rplugins[:2]) == successes) & k(rplugins.lift(2)).must(be_just(be_left)) & k(rplugins.lift(3)).must(be_just(be_left)))
def reboot_spec() -> Do: before = yield call_once_defined(reboot_test) json = yield N.e(dump_json(update_query)) yield nvim_command(f'CrmUpdateState {json}') yield seen_program('update_state') updated_path = yield await_k(check_path) yield nvim_command('CrmUpdate') yield nvim_command('CrmReboot') yield wait_for_function_undef(reboot_test) after = yield call_once_defined(reboot_test) return updated_path & (k(before) == 13) & (k(after) == 17)
def extension_spec() -> Do: dir = fixture_path('rplugin', name) extension_path = fixture_path('rplugin', ext_name) yield NS.lift(variable_set_prefixed('autostart', True)) yield NS.lift(variable_set(f'{name}_components', List(f'{ext_name}.ext'))) yield request('cram', f'dir:{dir}', name='extension_spec', extensions=[extension_path]) result1 = yield NS.lift(call_once_defined('XTest', timeout=1)) result2 = yield NS.lift(call_once_defined('XExtTest', timeout=1)) return (k(result1) == 13) & (k(result2) == 23)
def three(self) -> Expectation: layout = ViewTree.layout( SimpleLayout.cons('root', vertical=true), List( ViewTree.pane( SimplePane.cons(StrIdent('one'), geometry=ViewGeometry.cons(max_size=10))), ViewTree.pane( SimplePane.cons(StrIdent('two'), geometry=ViewGeometry.cons(max_size=10))), ViewTree.pane( SimplePane.cons(StrIdent('three'), geometry=ViewGeometry.cons(max_size=10))), )) data = SpecData.cons(layout) @do(TS[SpecData, List[PaneData]]) def go() -> Do: yield ui_open_simple_pane(StrIdent('one')) yield ui_open_simple_pane(StrIdent('two')) yield open_simple_pane(StrIdent('three')) panes = yield all_panes().state positions = panes / _.position yield TS.from_maybe(positions.lift_all(0, 1, 2), 'invalid number of panes') s, (p1, p2, p3) = self.run(go(), data) return k(p3 - p2) == (p2 - p1)
def four(self) -> Expectation: layout = ViewTree.layout( SimpleLayout.cons('root'), List( ViewTree.pane( SimplePane.cons('one', geometry=ViewGeometry.cons(min_size=30))), ViewTree.layout( SimpleLayout.cons('main', vertical=false), List( ViewTree.pane(SimplePane.cons('two')), ViewTree.layout( SimpleLayout.cons('sub1'), List( ViewTree.pane(SimplePane.cons('three')), ViewTree.layout( SimpleLayout.cons('sub2', vertical=false), List( ViewTree.pane(SimplePane.cons('four')), ViewTree.pane(SimplePane.cons('five')), )))))), )) data = SpecData.cons(layout) @do(TS[SpecData, None]) def go() -> Do: yield ui_open_simple_pane('one') yield ui_open_simple_pane('two') yield ui_open_simple_pane('three') yield ui_open_simple_pane('four') yield open_simple_pane('five') yield all_panes().state s, panes = self.run(go(), data) return k(panes).must(have_length(5))
def hs_spec() -> Do: yield NS.lift(variable_set_prefixed('autostart', True)) yield request('cram', f'hs:nvim-hs-ghcid', name='nvim-hs-ghcid', track=False) yield NS.lift(wait_for_command('GhcidStart', timeout=1)) return k(1) == 1
def python_path_spec() -> Do: dir = fixture_path('rplugin', 'path_spec') extra_path_pkg = fixture_path('rplugin', 'extra_path_pkg') yield NS.lift(variable_set_prefixed('autostart', True)) yield request('cram', f'dir:{dir}', name='path_spec', pythonpath=[extra_path_pkg]) result = yield NS.lift(call_once_defined('PathSpecTest', timeout=10)) return k(result) == 13
def two_vertical(self) -> Expectation: data = SpecData.cons(two_vertical) @do(TS[SpecData, None]) def go() -> Do: yield ui_open_simple_pane(StrIdent('one')) yield ui_open_simple_pane(StrIdent('two')) yield TS.modify(minimize_layout('right')) yield simple_render() yield all_panes().state self._wait(1) s, panes = self.run(go(), data) return k(panes.drop(1).map(lambda a: a.width)) == List(2)
def minimize(self) -> Expectation: data = SpecData.cons(three) @do(TS[SpecData, None]) def go() -> Do: yield ui_open_simple_pane(StrIdent('one')) yield ui_open_simple_pane(StrIdent('two')) yield open_simple_pane(StrIdent('three')) yield TS.modify(minimize_layout('sub')) yield simple_render() yield all_panes().state s, panes = self.run(go(), data) return k(panes[1:].map(lambda a: a.width)) == List(2, 2)
def one_spec() -> Do: yield NS.lift(present_venv(name)) yield update_data( rplugins=List(rplugin), venvs=List(name), active=List(active_rplugin), ready=List(name), ) yield request('update', 'flagellum') log_buffer = yield NS.inspect(lambda a: a.data.log_buffer) return k(log_buffer).must( contain(Echo.info(resources.updated_plugin(rplugin.name))))
def deactivate_spec() -> Do: yield await_k(flag_channel_id_becomes, not_equal(-1)) channel = yield flag_channel_id() yield await_k(flag_jobpid_becomes, greater(0)) yield nvim_command('CrmDeactivate') command_nonexistent = yield await_k(command_must_not_exist, 'FlagTest', timeout=10) quit_var = yield var_must_become('flagellum_quit', 1) pid = yield N.safe(nvim_call_tpe(int, 'jobpid', channel)) return ( command_nonexistent & k(pid).must(have_type(NError)) & quit_var )
def focus(self) -> Expectation: layout = ViewTree.layout( SimpleLayout.cons('main', vertical=true), List( ViewTree.pane(SimplePane.cons('one')), ViewTree.pane(SimplePane.cons('two')), ), ) data = SpecData.cons(layout) @do(TS[SpecData, None]) def go() -> Do: yield ui_open_simple_pane(StrIdent('one')) yield open_simple_pane(StrIdent('two')) yield all_panes().state yield TS.lift(pdata()) (s, r) = self.run(go(), data) return k(r) == List(FData(0, True), FData(1, False))
def one_sub(self) -> Expectation: layout = ViewTree.layout( SimpleLayout.cons('main', vertical=true), List( ViewTree.pane(SimplePane.cons('one')), ViewTree.layout( SimpleLayout.cons('sub', vertical=false), List( ViewTree.pane(SimplePane.cons('two')), ViewTree.pane(SimplePane.cons('three')), )), )) data = SpecData.cons(layout) @do(TS[SpecData, None]) def go() -> Do: yield ui_open_simple_pane(StrIdent('one')) yield ui_open_simple_pane(StrIdent('two')) yield open_simple_pane(StrIdent('three')) yield all_panes().state s, panes = self.run(go(), data) return k(panes).must(have_length(3))
def run_test_io(io: Callable[..., IO[Expectation]], *a: Any, **kw: Any) -> Expectation: return k(io(*a, **kw).attempt).must(be_right(match_with(lambda a: a)))
def minimized(self) -> Expectation: r = balance_sizes(List(10, 2), List(Just(10), Just(2)), List(.5, .5), List(False, True), 50) return k(r) == List(48, 2)
def cut(self) -> Expectation: r = balance_sizes(List(10, 20, 40), List(Nothing, Nothing, Nothing), List(0.2, 0.4, 0.4), List(False, False, False), 50) return k(r) == List(2, 14, 34)
def equal(self) -> Expectation: r = balance_sizes(List(0, 0, 0), List(Just(10), Just(10), Just(10)), List(1 / 3, 1 / 3, 1 / 3), List(False, False, False), 90) return k(r) == List(30, 30, 30)
def all(self) -> Expectation: r = balance_sizes(List(0, 0, 0), List(Just(10), Just(10), Just(40)), List(0.2, 0.4, 0.4), List(False, False, False), 50) return k(r) == List(10, 10, 30)
def unbounded(self) -> Expectation: r = balance_sizes(List(0, 0, 5), List(Just(10), Just(10), Nothing), List(1 / 3, 1 / 3, 1 / 3), List(False, False, False), 50) return k(r) == List(10, 10, 30)
def hackage_spec() -> Do: yield NS.lift(variable_set_prefixed('autostart', True)) yield request('cram', f'hackage:proteome', name='proteome') yield NS.lift(wait_for_function('ProAdd', timeout=1)) return k(1) == 1
def flag_jobpid_becomes(matcher: Matcher[int], timeout: float=1., interval: float=.25) -> Do: id = yield flag_channel_id() pid = yield nvim_call_tpe(int, 'jobpid', id) return k(pid).must(matcher)
def flag_channel_id_becomes(matcher: Matcher[int], timeout: float=1., interval: float=.25) -> Do: id = yield flag_channel_id() return k(id).must(matcher)
def pin_spec() -> Do: yield ui_open_simple_pane('one') yield open_simple_pane('three') s = yield all_panes().state return k(s).must(have_length(3))
def check_path() -> Do: state = yield nvim_call_json(f'ChromatinState') return k(state.rplugins.head.map(_.spec)).must(be_just(str(path)))
def one_spec() -> Do: yield update_data(rplugins=List(rplugin)) yield request('show_plugins') log_buffer = yield NS.inspect(lambda a: a.data.log_buffer) return k(log_buffer).must( contain(Echo.info(resources.show_plugins(dir, List(rplugin)))))
def hs_directory_spec(spec: str) -> Do: yield request('cram', spec, name=name) active = yield NS.inspect(lambda a: a.data.active) return k(active).must(contain(target))
def hs_dir_spec() -> Do: flag_dir = fixture_path('rplugin', 'flagellum.hs') yield NS.lift(variable_set_prefixed('autostart', True)) yield request('cram', f'hs_dir:{flag_dir}', name='flagellum') yield NS.lift(wait_for_function('FlagTest', timeout=1)) return k(1) == 1
def test(self) -> Expectation: return k(1) == 1
def log_matches(matcher: Matcher[List[str]]) -> Do: output = yield N.from_io(IO.file(test_config.log_file)) return k(output).must(matcher)