本文整理汇总了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
示例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)
示例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')
示例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))
示例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]
示例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)
示例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))
示例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
示例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
示例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))
示例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)
示例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
示例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')
示例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))
示例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