本文整理匯總了Python中input_reader.InputReader.add_mutually_exclusive_group方法的典型用法代碼示例。如果您正苦於以下問題:Python InputReader.add_mutually_exclusive_group方法的具體用法?Python InputReader.add_mutually_exclusive_group怎麽用?Python InputReader.add_mutually_exclusive_group使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類input_reader.InputReader
的用法示例。
在下文中一共展示了InputReader.add_mutually_exclusive_group方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_mutex_custom_options
# 需要導入模塊: from input_reader import InputReader [as 別名]
# 或者: from input_reader.InputReader import add_mutually_exclusive_group [as 別名]
def test_mutex_custom_options():
r = InputReader()
meg = r.add_mutually_exclusive_group(dest='rainbow', default='cloudy',
required=True)
assert meg._dest == 'rainbow'
assert meg._default == 'cloudy'
assert meg._required
with raises(ValueError) as e:
meg = r.add_mutually_exclusive_group(dest=23)
assert 'dest must be a str, given' in str(e.value)
with raises(ValueError) as e:
meg = r.add_mutually_exclusive_group(required='True')
assert 'required value must be a bool, given' in str(e.value)
示例2: test_read_mutex
# 需要導入模塊: from input_reader import InputReader [as 別名]
# 或者: from input_reader.InputReader import add_mutually_exclusive_group [as 別名]
def test_read_mutex():
r = InputReader()
meg = r.add_mutually_exclusive_group()
meg.add_boolean_key('red')
meg.add_boolean_key('blue')
meg.add_boolean_key('green')
inp = r.read_input(['red'])
assert inp.red
assert not inp.blue
assert not inp.green
with raises(ReaderError) as e:
inp = r.read_input(['red', 'blue'])
assert search(r'Only one of .* may be included', str(e.value))
# Unfortunately we cannot detect duplicate groups in different meg's
meg2 = r.add_mutually_exclusive_group()
meg2.add_boolean_key('red')
示例3: test_mutex_correct_call
# 需要導入模塊: from input_reader import InputReader [as 別名]
# 或者: from input_reader.InputReader import add_mutually_exclusive_group [as 別名]
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')
示例4: test_read_mutex_set_dest_set_required
# 需要導入模塊: from input_reader import InputReader [as 別名]
# 或者: from input_reader.InputReader import add_mutually_exclusive_group [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))
示例5: test_read_mutex_set_default
# 需要導入模塊: from input_reader import InputReader [as 別名]
# 或者: from input_reader.InputReader import add_mutually_exclusive_group [as 別名]
def test_read_mutex_set_default():
r = InputReader()
meg = r.add_mutually_exclusive_group(default='water')
meg.add_boolean_key('red')
meg.add_boolean_key('blue')
meg.add_boolean_key('green')
inp = r.read_input(['red'])
assert inp.red
assert inp.blue == 'water'
assert inp.green == 'water'
inp = r.read_input([])
assert inp.red == 'water'
assert inp.blue == 'water'
assert inp.green == 'water'
# Using default=SUPPRESS was the intended use case of default for meg's
meg = r.add_mutually_exclusive_group(default=SUPPRESS)
meg.add_boolean_key('pink')
meg.add_boolean_key('gray')
meg.add_boolean_key('cyan')
inp = r.read_input(['pink'])
assert inp.pink
assert 'gray' not in inp
assert 'cyan' not in inp
示例6: test_read_mutex_set_required
# 需要導入模塊: from input_reader import InputReader [as 別名]
# 或者: from input_reader.InputReader import add_mutually_exclusive_group [as 別名]
def test_read_mutex_set_required():
r = InputReader()
meg = r.add_mutually_exclusive_group(required=True)
meg.add_boolean_key('red')
meg.add_boolean_key('blue')
meg.add_boolean_key('green')
inp = r.read_input(['blue'])
assert inp.blue
assert not inp.red
assert not inp.green
with raises(ReaderError) as e:
inp = r.read_input([])
assert search(r'One and only one of .* must be included', str(e.value))
示例7: test_read_mutex_set_dest
# 需要導入模塊: from input_reader import InputReader [as 別名]
# 或者: from input_reader.InputReader import add_mutually_exclusive_group [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
示例8: read_input
# 需要導入模塊: from input_reader import InputReader [as 別名]
# 或者: from input_reader.InputReader import add_mutually_exclusive_group [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))
#.........這裏部分代碼省略.........
示例9: test_create_mutex_group
# 需要導入模塊: from input_reader import InputReader [as 別名]
# 或者: from input_reader.InputReader import add_mutually_exclusive_group [as 別名]
def test_create_mutex_group():
r = InputReader()
meg = r.add_mutually_exclusive_group()
assert meg._default is None
assert meg._dest is None
assert not meg._required
示例10: test_mutex_custom_options_str
# 需要導入模塊: from input_reader import InputReader [as 別名]
# 或者: from input_reader.InputReader import add_mutually_exclusive_group [as 別名]
def test_mutex_custom_options_str():
r = InputReader()
meg = r.add_mutually_exclusive_group(dest=str('rainbow'),
default=str('cloudy'))
assert meg._dest == 'rainbow'
assert meg._default == 'cloudy'