예제 #1
0
        def create3():
            Observable.create(throw_error).transduce(
                compose(
                    filtering(even), mapping(mul10))
                ).subscribe()

            self.assertRaises(RxException, create3)
예제 #2
0
 def test_chained_transducers(self):
     result = transduce(transducer=compose(mapping(lambda x: x * x),
                                           filtering(lambda x: x % 5 != 0),
                                           taking(6),
                                           dropping_while(lambda x: x < 15),
                                           distinct()),
                        reducer=appending(),
                        iterable=range(20))
     self.assertSequenceEqual(result, [16, 36, 49])
예제 #3
0
 def parse_group(lines):
     cmd, path_type, r, g, b = lines[0].split(';')
     color = float(r), float(g), float(b)
     strokes = transduce(
         compose(partitioning(lambda s: s.upper().startswith('MOVETO;')),
                 filtering(lambda lines: len(lines) > 1),
                 mapping(parse_path)), appending(), lines[1:])
     path = PltmePathGroup(strokes, path_type, color)
     return path
예제 #4
0
 def test_chained_transducers(self):
     result = transduce(transducer=compose(
                       mapping(lambda x: x*x),
                       filtering(lambda x: x % 5 != 0),
                       taking(6),
                       dropping_while(lambda x: x < 15),
                       distinct()),
                   reducer=appending(),
                   iterable=range(20))
     self.assertSequenceEqual(result, [16, 36, 49])
예제 #5
0
    def test_chained_transducers(self):
        result = transduce(transducer=compose(
                         mapping(lambda x: x*x),
                         filtering(lambda x: x % 5 != 0),
                         taking(6),
                         dropping_while(lambda x: x < 15),
                         distinct()),
                     iterable=range(20))

        expected = [16, 36, 49]
        for r, e in zip(result, expected):
            self.assertEqual(r, e)
예제 #6
0
    def test_chained_transducers(self):
        input = [0.0, 0.2, 0.8, 0.9, 1.1, 2.3, 2.6, 3.0, 4.1]
        output = CollectingSink()

        iterable_source(iterable=input,
                        target=transduce(
                            compose(pairwise(),
                                    mapping(lambda p: p[1] - p[0]),
                                    filtering(lambda d: d < 0.5),
                                    mapping(lambda _: "double-click")),
                            target=output()))

        result = list(output)
        self.assertListEqual(result, ['double-click', 'double-click', 'double-click', 'double-click', 'double-click'])
예제 #7
0
    def test_chained_transducers(self):
        result = transduce(
            transducer=compose(
                mapping(lambda x: x * x),
                filtering(lambda x: x % 5 != 0),
                taking(6),
                dropping_while(lambda x: x < 15),
                distinct(),
            ),
            iterable=range(20),
        )

        expected = [16, 36, 49]
        for r, e in zip(result, expected):
            self.assertEqual(r, e)
예제 #8
0
    def test_chained_transducers(self):
        input = [0.0, 0.2, 0.8, 0.9, 1.1, 2.3, 2.6, 3.0, 4.1]
        output = CollectingSink()

        iterable_source(iterable=input,
                        target=transduce(compose(
                            pairwise(), mapping(lambda p: p[1] - p[0]),
                            filtering(lambda d: d < 0.5),
                            mapping(lambda _: "double-click")),
                                         target=output()))

        result = list(output)
        self.assertListEqual(result, [
            'double-click', 'double-click', 'double-click', 'double-click',
            'double-click'
        ])
예제 #9
0
from transducer.transducers import filtering, mapping

import cosmic_ray.commands
import cosmic_ray.counting
import cosmic_ray.modules
import cosmic_ray.worker
from cosmic_ray.testing.test_runner import TestOutcome
from cosmic_ray.timing import Timer
from cosmic_ray.util import redirect_stdout
from cosmic_ray.work_db import use_db, WorkDB

LOG = logging.getLogger()

REMOVE_COMMENTS = mapping(lambda x: x.split('#')[0])
REMOVE_WHITESPACE = mapping(str.strip)
NON_EMPTY = filtering(bool)
CONFIG_FILE_PARSER = compose(REMOVE_COMMENTS, REMOVE_WHITESPACE, NON_EMPTY)


def _load_file(config_file):
    """Read configuration from a file.

    This reads `config_file`, yielding each non-empty line with
    whitespace and comments stripped off.
    """
    with open(config_file, 'rt', encoding='utf-8') as f:
        yield from transducer.lazy.transduce(CONFIG_FILE_PARSER, f)


@dsc.command('load')
def handle_load(config):
예제 #10
0
 def test_filtering(self):
     result = transduce(transducer=filtering(lambda w: 'x' in w),
                        reducer=appending(),
                        iterable='socks in box fox on clocks'.split())
     self.assertListEqual(result, ['box', 'fox'])
예제 #11
0
 def create():
     return xs.transduce(compose(filtering(even), mapping(mul10)))
예제 #12
0
        def create3():
            Observable.create(throw_error).transduce(
                compose(filtering(even), mapping(mul10))).subscribe()

            self.assertRaises(RxException, create3)
예제 #13
0
 def create2():
     Observable.empty().transduce(
         compose(filtering(even),
                 mapping(mul10))).subscribe_(noop, noop, throw_error)
예제 #14
0
 def create():
     Observable.throw(RxException()).transduce(
         compose(filtering(even),
                 mapping(mul10))).subscribe_(noop, throw_error)
예제 #15
0
파일: cli.py 프로젝트: donkirkby/cosmic-ray
import cosmic_ray.commands
import cosmic_ray.counting
import cosmic_ray.modules
import cosmic_ray.json_util
import cosmic_ray.worker
import cosmic_ray.testing
import cosmic_ray.timing
from cosmic_ray.work_db import use_db, WorkDB


LOG = logging.getLogger()

REMOVE_COMMENTS = mapping(lambda x: x.split('#')[0])
REMOVE_WHITESPACE = mapping(str.strip)
NON_EMPTY = filtering(bool)
CONFIG_FILE_PARSER = compose(REMOVE_COMMENTS,
                             REMOVE_WHITESPACE,
                             NON_EMPTY)


def _load_file(config_file):
    """Read configuration from a file.

    This reads `config_file`, yielding each non-empty line with
    whitespace and comments stripped off.
    """
    with open(config_file, 'rt', encoding='utf-8') as f:
        yield from transducer.lazy.transduce(CONFIG_FILE_PARSER, f)

예제 #16
0
 def test_filtering(self):
     result = transduce(transducer=filtering(lambda w: 'x' in w),
                        reducer=appending(),
                        iterable='socks in box fox on clocks'.split())
     self.assertListEqual(result, ['box', 'fox'])
예제 #17
0
 def create():
     return xs.transduce(compose(filtering(even), mapping(mul10)))
예제 #18
0
 def create():
     Observable.throw_exception(RxException()).transduce(
         compose(
             filtering(even), mapping(mul10))
         ).subscribe(noop, throw_error)
예제 #19
0
 def create2():
     Observable.empty().transduce(
         compose(
             filtering(even), mapping(mul10))
         ).subscribe(noop, noop, throw_error)