コード例 #1
0
ファイル: tmux_size_spec.py プロジェクト: tek/chiasma-py
    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))
コード例 #2
0
 def eff_map(self):
     a, b = self._r
     c = -1
     t = Right(List(Just(Right(a)), Just(Left(c)), Empty()))
     target = Right(List(Just(Right(a + b)), Just(Left(c)), Empty()))
     res = t.effs(3).map(_ + b)
     res.value.should.equal(target)
コード例 #3
0
 def eff_flat_io_empty(self):
     t = IO.now(List(Right(Empty())))
     target = List(Right(Empty()))
     res = (t.effs(
         4, List, Either, Maybe,
         Either).flat_map(lambda x: IO.now(List(Right(Just(Right(1)))))))
     res.value.run().should.equal(target)
コード例 #4
0
ファイル: eff_spec.py プロジェクト: yuhangwang/amino
 def eff_flat_task(self):
     a, b = self._r
     t = Task.now(List(Right(Just(Right(a)))))
     target = List(Right(Just(Right(a + b))))
     res = (t.effs(4, List, Either, Maybe, Either).flat_map(
         lambda x: Task.now(List(Right(Just(Right(x + b)))))))
     res.value.run().should.equal(target)
コード例 #5
0
ファイル: list_spec.py プロジェクト: GitHub-Notables/amino
 def unzip(self):
     a = 13
     b = 29
     l = List((a, a), (b, b), (a, a))
     l1, l2 = l.unzip
     l1.should.equal(l2)
     l1.should.equal(List(a, b, a))
コード例 #6
0
 def eff_flat(self):
     a, b = self._r
     t = List(Just(Right(Just(a))))
     target = List(Just(Right(Just(a + b))))
     res = (t.effs(
         3, Maybe, Either,
         Maybe).flat_map(lambda x: List(Just(Right(Just(x + b))))))
     res.value.should.equal(target)
コード例 #7
0
 def substitute_lnums(self) -> None:
     lines = List('sooo...In module imported from: asdf',
                  'amino/maybe.py:116:5: error: broken',
                  'foo/bar/__coconut__.py:22: error: nutt')
     return
     process_output(lines).should.equal(
         List(Map(lnum=82, text='broken', valid=1, maker_name='mypy',
                  col=5)))
コード例 #8
0
ファイル: lazy_list_spec.py プロジェクト: yuhangwang/amino
 def zip(self) -> None:
     a = 1
     b = 2
     ab = (a, b)
     l1 = LazyList((a, a, a, a), chunk_size=1)
     l2 = LazyList((b, b, b, b), chunk_size=1)
     l1[1]
     z = l1.zip(l2)
     z.strict.should.equal(List(ab, ab))
     z.drain.should.equal(List(ab, ab, ab, ab))
コード例 #9
0
 def __str__(self):
     enum = '{}x{}, {}x{}'.format(
         self.latest_season,
         self.latest_episode,
         self.season,
         self.next_episode,
     )
     tvid = List(self.tvdb_id) if self.tvdb_id else List()
     extra = (List(self.canonical_name, self.name) + tvid +
              List(enum, self.next_episode_date))
     return '{}({})'.format(self.__class__.__name__, extra.mk_string(', '))
コード例 #10
0
ファイル: read_conf_spec.py プロジェクト: tek/chromatin.py
 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)))
コード例 #11
0
ファイル: update_spec.py プロジェクト: tek/chromatin.py
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))))
コード例 #12
0
 def _getitem(self) -> None:
     f = __[1]
     a = 13
     f((1, a, 2)).should.equal(a)
     g = self.__.filter(self._ > 1)[1]
     b = 6
     g(List(4, 1, b)).should.equal(b)
     h = self._.x[0]
     h(Just(List(a))).should.equal(a)
     i = self._.x[0].length
     l = 3
     i(Just(List(Lists.range(3)))).should.equal(l)
コード例 #13
0
ファイル: lens_spec.py プロジェクト: yuhangwang/amino
    def tuple_(self):
        x, y, z = 11, 22, 33

        def mod(a):
            a[0][1].a = B(y)
            return a[0], B(x), lens(a[2]).b.set(z)

        b = List(B(B(0)), B(B(1)), B(B(2)))
        a = A(b)
        l1 = lens().b
        l2 = lens().b[0].a
        l3 = lens().b[2]
        l = lens(a).tuple_(l1, l2, l3)
        target = A(List(B(B(x)), B(B(y)), B(B(2), z)))
        l.modify(mod).should.equal(target)
コード例 #14
0
ファイル: lens_spec.py プロジェクト: GitHub-Notables/amino
    def tuple_(self):
        x, y, z = 11, 22, 33

        def mod(a):
            a[0][1].a = B(y)
            return a[0], B(x), bind(a[2]).b.set(z)

        b = List(B(B(0)), B(B(1)), B(B(2)))
        a = A(b)
        l1 = lens.GetAttr('b')
        l2 = lens.GetAttr('b')[0].GetAttr('a')
        l3 = lens.GetAttr('b')[2]
        l = lens.Tuple(l1, l2, l3)
        target = A(List(B(B(x)), B(B(y)), B(B(2), z)))
        l.modify(mod)(a).should.equal(target)
コード例 #15
0
ファイル: lazy_list_spec.py プロジェクト: yuhangwang/amino
    def collect(self) -> None:
        def f(a: int, n: str) -> Maybe[str]:
            return Just(n) if a % 2 == 0 else Nothing

        l: LazyList = LazyList((a, str(a)) for a in range(10))
        l2 = l.collect(tupled2(f))
        l2.drain.should.equal(List('0', '2', '4', '6', '8'))
コード例 #16
0
ファイル: eval.py プロジェクト: tangleibest/untitled
    def _value(self) -> A:
        C = Callable[[Any], Eval[Any]]

        def loop_compute(
                c: Compute[Any, Any], fs: List[C]
        ) -> Tuple[bool, Union[Tuple[Eval[Any], List[C]], Any]]:
            cc = c.start()
            return ((True, (cc.start(), fs.cons(c.run).cons(cc.run)))
                    if isinstance(cc, Compute) else
                    (True, (c.run(cc._value()), fs)))

        def loop_other(
                e: Eval[Any], fs: List[C]
        ) -> Tuple[bool, Union[Tuple[Eval[Any], List[C]], Any]]:
            return fs.detach_head.map2(lambda fh, ft: (True, (fh(e._value(
            )), ft))) | (False, e._value())

        @tco
        def loop(
                e: Eval[Any], fs: List[C]
        ) -> Tuple[bool, Union[Tuple[Eval[Any], List[C]], Any]]:
            return (loop_compute(e, fs)
                    if isinstance(e, Compute) else loop_other(e, fs))

        return loop(self, List())
コード例 #17
0
 def stackage(self, a: HsStackageRplugin) -> Do:
     stack = yield N.from_io(stack_exe())
     return Subprocess(stack,
                       List('install', a.dep),
                       self.rplugin.rplugin.name,
                       600,
                       env=None)
コード例 #18
0
ファイル: gen_state.py プロジェクト: yangyang202/DA_GP9
def state_task(
    tpe: str,
    path: str,
    tvar: List[str] = Nil,
    class_extra: str = '',
    meta_extra: str = '',
    ctor_extra: str = '',
    extra_import: List[str] = Nil,
    extra: str = '',
) -> CodegenTask:
    tpar = tvar.map(lambda a: f'{a}, ').mk_string('')
    tvars = tvar.map(lambda a: f'{a} = TypeVar(\'{a}\')').join_lines
    tpe_import = f'from {path} import {tpe}'
    subs = List(
        (r'\bF\[', f'{tpe}[{tpar}'),
        (r'\bF\b', tpe),
        ('StateT\[', f'{tpe}State[{tpar}'),
        ('StateT', f'{tpe}State'),
        ('{tpar}', tpar),
        ('{tvar}', tvars),
        ('{f_import}', tpe_import),
        ('{class_extra}', class_extra),
        ('{meta_extra}', meta_extra),
        ('{ctor_extra}', ctor_extra),
        ('{extra_import}', extra_import.join_lines),
        ('{extra}', extra),
        ('StateBase', 'StateT'),
    )
    return CodegenTask(template_path, subs, Nil)
コード例 #19
0
def create_pane_from_data(window: Window, pane: Pane, dir: Path) -> Do:
    target_window = yield TmuxIO.from_maybe(window.id,
                                            lambda: f'{window} has no id')
    args = List('-t', window_id(target_window), '-d', '-P', '-c', dir)
    panes = yield tmux_data_cmd('split-window', args, cmd_data_pane)
    yield TmuxIO.from_maybe(
        panes.head, lambda: f'no output when creating pane in {window}')
コード例 #20
0
 def hackage(self, a: HsHackageRplugin) -> Do:
     cabal = yield N.from_io(cabal_exe())
     return Subprocess(cabal,
                       List('install', a.dep),
                       self.rplugin.rplugin.name,
                       600,
                       env=None)
コード例 #21
0
 def dir_rplugin(self, rplugin: DirRplugin) -> Do:
     venv = yield venv_from_rplugin(rplugin)
     python_exe = venv.meta.python_executable
     bin_path = venv.meta.bin_path
     plugin_path = Path(rplugin.spec) / rplugin.name / '__init__.py'
     yield start_python_rplugin_host(rplugin, python_exe, bin_path,
                                     plugin_path, List(rplugin.spec))
コード例 #22
0
 def add_link(self, release, url):
     if release.has_url(url):
         text = 'Release {rel} already contains link "{link}"'
     else:
         self._add_links(release, List(url))
         text = 'Adding link "{link}" to release {rel}'
     self.log.info(text.format(link=url, rel=release.release))
コード例 #23
0
ファイル: list.py プロジェクト: tangleibest/untitled
    def traverse(self, fa: List[A], f: Callable, tpe: type):
        monad = Applicative.fatal(tpe)

        def folder(z, a):
            return monad.map2(z.product(f(a)), lambda l, b: l.cat(b))

        return fa.fold_left(monad.pure(List()))(folder)
コード例 #24
0
 def filter_by_metadata(self, series=None, season=None, episode=None):
     filters = List(
         Maybe(series) / (lambda a: Release.name == a),
         Maybe(season) / str / (lambda a: Release.season == a),
         Maybe(episode) / str / (lambda a: Release.episode == a),
     )
     return self.filter_release(*filters.join)
コード例 #25
0
ファイル: base.py プロジェクト: tek/chromatin.py
 def gather(self, po: ProgGather,
            output: Gather[A]) -> Prog[List[Either[IOException, A]]]:
     return Prog.pure(
         List(
             Right(
                 GatherSubprocessResult(
                     SubprocessResult(0, Nil, Nil, self.venv.name)))))
コード例 #26
0
ファイル: tmux_size_spec.py プロジェクト: tek/chiasma-py
    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)
コード例 #27
0
 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))
コード例 #28
0
 def zip(
     self,
     fa: IdState[S, A],
     fb: IdState[S, A],
     *fs: IdState[S, A],
 ) -> IdState[S, List[A]]:
     v = ListTraverse().sequence(List(fa, fb, *fs), IdState)  # type: ignore
     return cast(IdState[S, List[A]], v)
コード例 #29
0
 def dir(self, a: HsStackDirRplugin) -> Do:
     stack = yield N.from_io(stack_exe())
     return Subprocess(stack,
                       List('install'),
                       self.rplugin.rplugin.name,
                       600,
                       cwd=a.dir,
                       env=None)
コード例 #30
0
ファイル: either.py プロジェクト: yangyang202/DA_GP9
 def zip(
     self,
     fa: EitherState[E, S, A],
     fb: EitherState[E, S, A],
     *fs: EitherState[E, S, A],
 ) -> EitherState[E, S, List[A]]:
     v = ListTraverse().sequence(List(fa, fb, *fs),
                                 EitherState)  # type: ignore
     return cast(EitherState[E, S, List[A]], v)