当前位置: 首页>>代码示例>>Python>>正文


Python input_reader.InputReader类代码示例

本文整理汇总了Python中input_reader.InputReader的典型用法代码示例。如果您正苦于以下问题:Python InputReader类的具体用法?Python InputReader怎么用?Python InputReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了InputReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_regex_case_definition

def test_regex_case_definition():
    r = InputReader()
    a = r.add_regex_line('red', r'funny\d+DOG')
    assert a.name == 'red'
    assert a._regex.pattern == r'funny\d+DOG'
    if sys.version_info.major == 3:
        assert a._regex.flags == (re.IGNORECASE | re.UNICODE)
    else:
        assert a._regex.flags == re.IGNORECASE
    regex = re.compile(r'funny\d+dog', re.IGNORECASE)
    b = r.add_regex_line('blue', regex)
    assert b.name == 'blue'
    assert b._regex == regex
    c = r.add_regex_line('green', r'funny\d+DOG', case=True)
    assert c.name == 'green'
    assert c._regex.pattern == r'funny\d+DOG'
    if sys.version_info.major == 3:
        assert c._regex.flags == re.UNICODE
    else:
        assert c._regex.flags == 0
    regex = re.compile(r'funny\d+dog', re.IGNORECASE)
    # Case is ignored if a regex flag is given
    d = r.add_regex_line('gray', regex, case=True)
    assert d.name == 'gray'
    assert d._regex == regex
开发者ID:SethMMorton,项目名称:input_reader,代码行数:25,代码来源:test_regex.py

示例2: test_block_ignoreunknown_definition

def test_block_ignoreunknown_definition():
    r = InputReader()
    a = r.add_block_key('red', ignoreunknown=True)
    assert a._ignoreunknown
    with raises(ValueError) as e:
        b = r.add_block_key('blue', ignoreunknown='True')
    assert 'ignoreunknown must be bool' in str(e.value)
开发者ID:SethMMorton,项目名称:input_reader,代码行数:7,代码来源:test_block.py

示例3: test_case_sensitivity_at_class_level

def test_case_sensitivity_at_class_level():
    ir = InputReader(case=True)
    assert ir._case
    l = ir.add_line_key('RED')
    assert l._case
    with raises(ValueError):
        ir2 = InputReader(case='True')
开发者ID:SethMMorton,项目名称:input_reader,代码行数:7,代码来源:test_keywords.py

示例4: test_block_repeat_in_definition

def test_block_repeat_in_definition():
    # You cannot repeat keys
    r = InputReader()
    r.add_block_key('red')
    with raises(ReaderError) as e:
        r.add_block_key('red')
    assert search(r'The keyname "\w+" has been defined twice', str(e.value))
开发者ID:SethMMorton,项目名称:input_reader,代码行数:7,代码来源:test_block.py

示例5: __init__

    def __init__(self):
        input_reader = InputReader()
        self.state = input_reader.read(0)
        self.output_writer = OutputWriter('naive')
        self.num_rows = self.state['numRows']
        self.num_cols = self.state['numCols']
        self.num_drones = self.state['numDrones']
        self.num_turns = self.state['numTurns']
        self.max_payload = self.state['maxPayload']
        self.num_product_types = self.state['numProductTypes']
        self.product_weights = self.state['productWeights']
        self.num_warehouses = self.state['numWarehouses']
        # warehouse: liste auf dicts: x, y, items -> itemstock
        self.warehouse_data = self.state['warehousesData']
        # order data: liste auf dicts: x, y, numorders, items
        self.order_data = self.state['orderData']

        # get list of items
        self.item_lists = numpy.zeros((len(self.order_data), len(self.product_weights)), dtype=int)

        self.turns_used = numpy.zeros(self.num_drones)
        self.drone_location = numpy.zeros((self.num_drones, 2))

        for order_idx in numpy.arange(len(self.order_data)):
            for item in self.order_data[order_idx]['items']:
                self.item_lists[order_idx][item] += 1

        for n in numpy.arange(self.num_drones):
            self.drone_location[n] = [0, 0]
开发者ID:pawni,项目名称:hashcode,代码行数:29,代码来源:naive_optimiser.py

示例6: test_block_case_definition

def test_block_case_definition():
    r = InputReader()
    a = r.add_block_key('red', case=True)
    assert a._case
    with raises(ValueError) as e:
        r.add_block_key('blue', case='True')
    assert 'case must be bool' in str(e.value)
开发者ID:SethMMorton,项目名称:input_reader,代码行数:7,代码来源:test_block.py

示例7: test_unterminated_block

def test_unterminated_block():
    r = InputReader(ignoreunknown=True)
    a = r.add_block_key('red')
    a.add_boolean_key('rose')
    with raises(ReaderError) as e:
        r.read_input(['red', 'rose'])
    assert search('Unterminated block', str(e.value))
开发者ID:SethMMorton,项目名称:input_reader,代码行数:7,代码来源:test_block.py

示例8: test_block_correct_call

def test_block_correct_call():
    r = InputReader()
    a = r.add_block_key(str('red'))
    assert a.name == 'red'
    assert a._end == 'end'
    assert not a._case
    assert not a._ignoreunknown
开发者ID:SethMMorton,项目名称:input_reader,代码行数:7,代码来源:test_block.py

示例9: test_block_read_end

def test_block_read_end():
    r = InputReader()
    a = r.add_block_key('red', end='subend')
    a.add_boolean_key('rose', default=False)
    inp = r.read_input(['red', 'rose', 'subend'])
    assert inp.red.rose
    inp = r.read_input(['red', 'subend'])
    assert not inp.red.rose
开发者ID:SethMMorton,项目名称:input_reader,代码行数:8,代码来源:test_block.py

示例10: test_regex_repeat_in_definition

def test_regex_repeat_in_definition():
    # You cannot repeat keys
    r = InputReader()
    r.add_regex_line('red', r'test')
    with raises(ReaderError) as e:
        r.add_regex_line('red', r'tax')
    regex = r'The handle "\w+" has been defined twice'
    assert search(regex, str(e.value))
开发者ID:SethMMorton,项目名称:input_reader,代码行数:8,代码来源:test_regex.py

示例11: test_block_end_definition

def test_block_end_definition():
    r = InputReader()
    a = r.add_block_key('red', end='subend')
    assert a._end == 'subend'
    a = r.add_block_key('green', end=str('subending'))
    assert a._end == 'subending'
    with raises(ValueError) as e:
        r.add_block_key('blue', end=23)
    assert 'end must be str' in  str(e.value)
开发者ID:SethMMorton,项目名称:input_reader,代码行数:9,代码来源:test_block.py

示例12: test_regex_correct_call_Str

def test_regex_correct_call_Str():
    r = InputReader()
    a = r.add_regex_line(str('red'), str(r'funny\d+dog'))
    assert a.name == 'red'
    assert a._regex.pattern == r'funny\d+dog'
    regex = re.compile(str(r'funny\d+dog'))
    b = r.add_regex_line(str('blue'), regex)
    assert b.name == 'blue'
    assert b._regex == regex
开发者ID:SethMMorton,项目名称:input_reader,代码行数:9,代码来源:test_regex.py

示例13: test_mutex_correct_call

def test_mutex_correct_call():
    r = InputReader()
    meg = r.add_mutually_exclusive_group()
    a = meg.add_boolean_key('red')
    assert a.name == 'red'
    assert a._action
    assert not a._default
    meg.add_boolean_key('blue')
    with raises(ReaderError):
        meg.add_boolean_key('red')
开发者ID:SethMMorton,项目名称:input_reader,代码行数:10,代码来源:test_mutually_excusive_group.py

示例14: test_read_mutex_set_dest_set_required

def test_read_mutex_set_dest_set_required():
    r = InputReader()
    meg = r.add_mutually_exclusive_group(required=True, dest='color')
    meg.add_boolean_key('red')
    meg.add_boolean_key('blue')
    meg.add_boolean_key('green')
    r.add_boolean_key('cyan')

    with raises(ReaderError) as e:
        inp = r.read_input(['cyan'])
    assert search(r'One and only one of .* must be included', str(e.value))
开发者ID:SethMMorton,项目名称:input_reader,代码行数:11,代码来源:test_mutually_excusive_group.py

示例15: test_regex_correct_call

def test_regex_correct_call():
    r = InputReader()
    a = r.add_regex_line('red', r'funny\d+dog')
    assert a.name == 'red'
    assert a._regex.pattern == r'funny\d+dog'
    assert not a._case
    regex = re.compile(r'funny\d+dog')
    b = r.add_regex_line('blue', regex)
    assert b.name == 'blue'
    assert b._regex == regex
    assert not b._case
开发者ID:SethMMorton,项目名称:input_reader,代码行数:11,代码来源:test_regex.py


注:本文中的input_reader.InputReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。