當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。