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


Python InputReader.add_boolean_key方法代码示例

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


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

示例1: test_ignoreunknown_actually_ignores_unknown

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_boolean_key [as 别名]
def test_ignoreunknown_actually_ignores_unknown(setup):
    # Ignore unknown keys
    parse_string = setup[-1]
    reader = InputReader(comment='//', ignoreunknown=True)
    reader.add_boolean_key('red')
    reader.add_line_key('path')
    inp = reader.read_input(parse_string)
    with raises(AttributeError):
        inp.blue
开发者ID:SethMMorton,项目名称:input_reader,代码行数:11,代码来源:test_read_file.py

示例2: test_unknown_keys_cause_failure

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_boolean_key [as 别名]
def test_unknown_keys_cause_failure(setup):
    # Don't ignore unknown keys
    parse_string = setup[-1]
    reader = InputReader(comment='//', ignoreunknown=False)
    reader.add_boolean_key('red')
    reader.add_line_key('path')
    with raises(ReaderError) as e:
        reader.read_input(parse_string)
    assert 'Unrecognized key' in str(e.value)
开发者ID:SethMMorton,项目名称:input_reader,代码行数:11,代码来源:test_read_file.py

示例3: test_comments_are_handled_correctly

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_boolean_key [as 别名]
def test_comments_are_handled_correctly(setup):
    parse_string = setup[-1]
    reader = InputReader(comment='#')
    reader.add_boolean_key('red')
    reader.add_boolean_key('blue')
    reader.add_line_key('path')
    with raises(ReaderError) as e:
        reader.read_input(parse_string)
    regex = r'expected \d+ arguments, got \d+'
    assert search(regex, str(e.value))
开发者ID:SethMMorton,项目名称:input_reader,代码行数:12,代码来源:test_read_file.py

示例4: test_read_mutex_set_dest_set_required

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_boolean_key [as 别名]
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,代码行数:13,代码来源:test_mutually_excusive_group.py

示例5: test_read_mutex_set_dest

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_boolean_key [as 别名]
def test_read_mutex_set_dest():
    r = InputReader()
    # This is the best way to use meg's
    meg = r.add_mutually_exclusive_group(dest='color')
    meg.add_boolean_key('red', action='red')
    meg.add_boolean_key('blue', action='blue')
    meg.add_boolean_key('green', action='green')
    meg.add_boolean_key('pink', action='pink')
    meg.add_boolean_key('gray', action='pink')
    meg.add_boolean_key('cyan', action='cyan')
    r.add_boolean_key('white')
    inp = r.read_input(['cyan', 'white'])
    assert inp.color == 'cyan'
    assert inp.white
    assert 'red' not in inp
    assert 'blue' not in inp
    assert 'green' not in inp
    assert 'pink' not in inp
    assert 'gray' not in inp
    assert 'cyan' not in inp
开发者ID:SethMMorton,项目名称:input_reader,代码行数:22,代码来源:test_mutually_excusive_group.py

示例6: test_string_default_at_class_level

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_boolean_key [as 别名]
def test_string_default_at_class_level():
    ir = InputReader(default='roses')
    assert ir._default == 'roses'
    b = ir.add_boolean_key('RED')
    assert b._default == 'roses'
开发者ID:SethMMorton,项目名称:input_reader,代码行数:7,代码来源:test_keywords.py

示例7: test_suppress_at_class_level

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_boolean_key [as 别名]
def test_suppress_at_class_level():
    ir = InputReader(default=SUPPRESS)
    assert ir._default is SUPPRESS
    b = ir.add_boolean_key('RED')
    assert b._default is SUPPRESS
开发者ID:SethMMorton,项目名称:input_reader,代码行数:7,代码来源:test_keywords.py

示例8: read_input

# 需要导入模块: from input_reader import InputReader [as 别名]
# 或者: from input_reader.InputReader import add_boolean_key [as 别名]
def read_input(input_file):
    '''Defines what to expect from the input file and then
    reads it in.'''

    # Creates an input reader instance
    reader = InputReader(default=SUPPRESS)

    # Rate parameter, either rate or lifetime, not both
    rate = reader.add_mutually_exclusive_group(required=True)
    # The units are s, ns, ps, or fs.  The default is ps.
    rate.add_line_key('lifetime', type=float,
                      glob={'len' : '?',
                            'type' : ('ps', 'fs', 'ns', 's'),
                            'default' : 'ps'})
    rate.add_line_key('rate', type=float,
                      glob={'len' : '?',
                            'type' : ('thz', 'phz', 'ghz', 'hz'),
                            'default' : 'thz'})

    # The range of the X-axis
    reader.add_line_key('xlim', type=[int, int], default=(1900, 2000))
    reader.add_boolean_key('reverse', action=True, default=False)

    # Read in the raw data.  
    reader.add_line_key('raw', type=[], glob={'len':'*', 'join':True, },
                               default=None, case=True)

    # Read in the peak data.  The wavenumber and height is required.
    # The Lorentzian and Gaussian widths are defaulted to 10 if not given.
    floatkw = {'type' : float, 'default' : 10.0}
    reader.add_line_key('peak', required=True, repeat=True, type=[float,float],
                                keywords={'g':floatkw, 'l':floatkw,
                                          'num' : {'type':int,'default':-1}})

    # Read the exchange information.
    reader.add_line_key('exchange', repeat=True, type=[int, int],
                                    glob={'type' : float,
                                          'default' : 1.0,
                                          'len' : '?'})
    reader.add_boolean_key('nosym', action=False, default=True,
                           dest='symmetric_exchange')

    # Actually read the input file
    args = reader.read_input(input_file)

    # Make sure the filename was given correctly and read in data
    if args.raw:
        args.add('rawName', args.raw)
        args.raw = loadtxt(abs_file_path(args.raw))

    # Make the output file path absolute if given
    args.data = abs_file_path(args.data) if 'data' in args else ''

    if 'save_plot_script' in args:
        args.save_plot_script = abs_file_path(args.save_plot_script)
    else:
        args.save_plot_script = ''

    # Adjust the input rate or lifetime to wavenumbers
    if 'lifetime' in args:
        convert = { 'ps' : 1E-12, 'ns' : 1E-9, 'fs' : 1E-15, 's' : 1 }
        args.add('k', 1 / ( convert[args.lifetime[1]] * args.lifetime[0] ))
    else:
        convert = { 'thz' : 1E12, 'ghz' : 1E9, 'phz' : 1E15, 'hz' : 1 }
        args.add('k', convert[args.rate[1]] * args.rate[0])
    args.k *= HZ2WAVENUM / ( 2 * pi )

    # Parse the vibrational input
    num, vib, Gamma_Lorentz, Gamma_Gauss, heights, rel_rates, num_given = (
                                                    [], [], [], [], [], [], [])
    for peak in args.peak:
        # Vibration #
        num.append(peak[2]['num'])
        num_given.append(False if peak[2]['num'] < 0 else True)
        # Angular frequency
        vib.append(peak[0])
        # Relative peak heights
        heights.append(peak[1])
        # Default Gaussian or Lorentzian width or relative rate
        Gamma_Lorentz.append(peak[2]['l'])
        Gamma_Gauss.append(peak[2]['g'])

    # Either all or none of the numbers must be given explicitly
    if not (all(num_given) or not any(num_given)):
        raise ReaderError('All or none of the peaks must '
                          'be given numbers explicitly')
    # If the numbers were give, make sure there are no duplicates
    if all(num_given):
        if len(num) != len(set(num)):
            raise ReaderError('Duplicate peaks cannot be given')
    # If none were given, number automatically
    else:
        num = range(1, len(num)+1, 1)

    args.add('num', array(num))
    args.add('vib', array(vib))
    args.add('heights', array(heights))
    args.add('Gamma_Lorentz', array(Gamma_Lorentz))
    args.add('Gamma_Gauss', array(Gamma_Gauss))

#.........这里部分代码省略.........
开发者ID:jensengrouppsu,项目名称:rapid,代码行数:103,代码来源:read_input.py


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