本文整理汇总了Python中types.SimpleNamespace类的典型用法代码示例。如果您正苦于以下问题:Python SimpleNamespace类的具体用法?Python SimpleNamespace怎么用?Python SimpleNamespace使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimpleNamespace类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _classify
def _classify(self):
"""
classify fixations
"""
if self.g_pool.app == "exporter":
return
if self.bg_task:
self.bg_task.cancel()
gaze_data = [gp.serialized for gp in self.g_pool.gaze_positions]
cap = SimpleNamespace()
cap.frame_size = self.g_pool.capture.frame_size
cap.intrinsics = self.g_pool.capture.intrinsics
cap.timestamps = self.g_pool.capture.timestamps
generator_args = (
cap,
gaze_data,
np.deg2rad(self.max_dispersion),
self.min_duration / 1000,
self.max_duration / 1000,
self.g_pool.min_data_confidence,
)
self.fixation_data = deque()
self.fixation_start_ts = deque()
self.fixation_stop_ts = deque()
self.bg_task = bh.IPC_Logging_Task_Proxy(
"Fixation detection", detect_fixations, args=generator_args
)
开发者ID:pupil-labs,项目名称:pupil,代码行数:31,代码来源:fixation_detector.py
示例2: setup_test_environment
def setup_test_environment(debug=None):
"""
Perform global pre-test setup, such as installing the instrumented template
renderer and setting the email backend to the locmem email backend.
"""
if hasattr(_TestState, 'saved_data'):
# Executing this function twice would overwrite the saved values.
raise RuntimeError(
"setup_test_environment() was already called and can't be called "
"again without first calling teardown_test_environment()."
)
if debug is None:
debug = settings.DEBUG
saved_data = SimpleNamespace()
_TestState.saved_data = saved_data
saved_data.allowed_hosts = settings.ALLOWED_HOSTS
# Add the default host of the test client.
settings.ALLOWED_HOSTS = list(settings.ALLOWED_HOSTS) + ['testserver']
saved_data.debug = settings.DEBUG
settings.DEBUG = debug
saved_data.email_backend = settings.EMAIL_BACKEND
settings.EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend'
saved_data.template_render = Template._render
Template._render = instrumented_test_render
mail.outbox = []
deactivate()
开发者ID:atombrella,项目名称:django,代码行数:34,代码来源:utils.py
示例3: who_flag_parse
def who_flag_parse(flags):
""" Parse WHO flags.
:param flags:
Flags to parse.
:returns:
A namespace object containing the following attributes:
:param operator:
Whether or not the user is an operator.
:param away:
Whether or not the user is away.
:param modes:
A set of the user's present modes (prefixes).
"""
ret = SimpleNamespace(operator=False, away=False, modes=set())
ret.operator = False
for char in flags:
if char == '*':
ret.operator = True
elif char == "G":
ret.away = True
elif char == "H":
ret.away = False
elif char not in numletters:
ret.modes.add(char)
else:
logger.debug("No known way to handle WHO flag %s", char)
return ret
开发者ID:bethebunny,项目名称:mircy,代码行数:34,代码来源:auxparse.py
示例4: read_data
def read_data(csv, config):
with open(config) as fin:
use = fin.readline().strip().split(',')
ref = fin.readline().strip()
with open(csv) as fin:
header = fin.readline().strip().split(',')
use.sort(key=lambda i: header.index(i))
data_matrix = np.array([], dtype=np.float).reshape(0, len(use))
ref_array = []
ref_data = None
for line in fin:
entry = line.strip().split(',')
use_data = []
del ref_data
for i, val in enumerate(entry):
label = header[i]
if label in use:
use_data.append(np.log(float(val)))
elif label == ref:
ref_data = int(val)
data_matrix = np.vstack((data_matrix, use_data))
ref_array.append(ref_data)
ret = SimpleNamespace()
ret.data_header = use
ret.data = data_matrix
ret.flag = ref_array
ret.samples = len(ref_array)
return ret
开发者ID:cuihaoleo,项目名称:exercises,代码行数:35,代码来源:julei.py
示例5: test_reinterpreter_comp
def test_reinterpreter_comp(self):
comp1 = L.pe('COMP({(x, y, (x, z)) for (x, y) in S '
'for (y, z) in T}, [], {})')
comp2 = L.pe('COMP({(x, x) for (x, y) in U}, [], {})')
spec1 = CompSpec.from_comp(comp1, self.manager.factory)
spec2 = CompSpec.from_comp(comp2, self.manager.factory)
# Dummy wrapper for what would be IncComp.
Dummy1 = SimpleNamespace()
Dummy1.spec = spec1
Dummy2 = SimpleNamespace()
Dummy2.spec = spec2
invs = {'Q': Dummy1, 'S': Dummy2}
# Boilerplate domain information regarding the comprehension.
constrs = []
constrs.extend(spec1.get_domain_constraints('Q'))
constrs.extend(spec2.get_domain_constraints('S'))
domain_subst = unify(constrs)
domain_subst = add_domain_names(domain_subst, {})
trans = CostReinterpreter(invs, domain_subst, {}, {})
cost = NameCost('Q')
cost = trans.process(cost)
cost = normalize(cost)
exp_cost_str = '(Q_x*Q_z)'
self.assertEqual(str(cost), exp_cost_str)
开发者ID:IncOQ,项目名称:incoq,代码行数:27,代码来源:test_interact.py
示例6: test_mcmcmc_step_parse
def test_mcmcmc_step_parse(capsys):
rand_gen = random.Random(4)
tmp_file = br.TempFile()
walker = SimpleNamespace(name="qwerty", proposed_score=None, score_history=[1.12, 3.42], current_score=3.42,
accept=lambda *_: print("Calling accept() method"), rand_gen=rand_gen, heat=0.25,
ice=False, lava=False, proposed_score_file=tmp_file)
# Accept higher score
tmp_file.write("7.90", mode="w")
mcmcmc.MCMCMC.step_parse(walker=walker, std=1.5)
assert walker.score_history == [1.12, 3.42, 7.9]
assert walker.proposed_score == 7.9
out, err = capsys.readouterr()
assert out == "Calling accept() method\n"
# Reject lower score
tmp_file.write("0.91", mode="w")
mcmcmc.MCMCMC.step_parse(walker=walker, std=3.1)
assert walker.score_history == [1.12, 3.42, 7.9, 0.91]
assert walker.proposed_score == 0.91
out, err = capsys.readouterr()
assert out == ""
# Accept lower score
tmp_file.write("3.3", mode="w")
mcmcmc.MCMCMC.step_parse(walker=walker, std=3.1)
assert walker.score_history == [1.12, 3.42, 7.9, 0.91, 3.3]
assert walker.proposed_score == 3.3
out, err = capsys.readouterr()
assert out == "Calling accept() method\n", print(out)
# Lava walker accepts any score
tmp_file.write("0.1", mode="w")
walker.lava = True
mcmcmc.MCMCMC.step_parse(walker=walker, std=3.1)
assert walker.score_history == [1.12, 3.42, 7.9, 0.91, 3.3, 0.1]
out, err = capsys.readouterr()
assert out == "Calling accept() method\n"
# Ice walker rejects any lower scores
tmp_file.write("3.4", mode="w")
walker.lava = False
walker.ice = True
mcmcmc.MCMCMC.step_parse(walker=walker, std=3.1)
assert walker.score_history == [1.12, 3.42, 7.9, 0.91, 3.3, 0.1, 3.4]
out, err = capsys.readouterr()
assert out == ""
# Do not allow history to grow over 1000 items long
walker.score_history = [1 for _ in range(1000)]
assert len(walker.score_history) == 1000
mcmcmc.MCMCMC.step_parse(walker, 3.1)
assert len(walker.score_history) == 1000
assert walker.score_history[-1] == 3.4
开发者ID:biologyguy,项目名称:RD-MCL,代码行数:59,代码来源:test_mcmcmc.py
示例7: __mock_output__
def __mock_output__(self, open_method=False, close_method=False):
output = SimpleNamespace()
output.on_update = MagicMock(spec=(""))
if open_method:
output.open = MagicMock(spec=(""))
if close_method:
output.close = MagicMock(spec=(""))
return output
开发者ID:SchweizerischeBundesbahnen,项目名称:cimon_controller,代码行数:8,代码来源:test_cimon.py
示例8: registries
def registries(hass):
"""Registry mock setup."""
from types import SimpleNamespace
ret = SimpleNamespace()
ret.entity = mock_registry(hass)
ret.device = mock_device_registry(hass)
ret.area = mock_area_registry(hass)
return ret
开发者ID:boced66,项目名称:home-assistant,代码行数:8,代码来源:test_smart_home.py
示例9: get_mappings
def get_mappings(efo_mapping_file, snp_2_gene_file):
mappings = SimpleNamespace()
mappings.trait_2_efo, mappings.unavailable_efo = \
load_efo_mapping(efo_mapping_file)
mappings.consequence_type_dict = \
CT.process_consequence_type_file(snp_2_gene_file)
return mappings
开发者ID:cyenyxe,项目名称:eva-cttv-pipeline,代码行数:9,代码来源:clinvar_to_evidence_strings.py
示例10: get_noise_record
def get_noise_record(self):
noise = SimpleNamespace()
noise.x1 = self.x[0]
noise.w_sequence = self.w[:]
noise.v_sequence = self.v[:]
noise.n_sequence = list(np.array(self.noise).flatten())
return noise
开发者ID:eliasrg,项目名称:SURF2017,代码行数:9,代码来源:measurements.py
示例11: test_chain_get_best_walker
def test_chain_get_best_walker():
walker1 = SimpleNamespace(current_score=35)
walker2 = SimpleNamespace(current_score=15)
chain = SimpleNamespace(walkers=[walker1, walker2], get_best_walker=mcmcmc._Chain.get_best_walker)
assert chain.get_best_walker(chain) == walker1
chain.walkers = [walker2, walker1]
assert chain.get_best_walker(chain) == walker1
开发者ID:biologyguy,项目名称:RD-MCL,代码行数:9,代码来源:test_mcmcmc.py
示例12: test_chain_get_cold_walker
def test_chain_get_cold_walker():
walker1 = SimpleNamespace(heat=0.1)
walker2 = SimpleNamespace(heat=0.4)
chain = SimpleNamespace(walkers=[walker1, walker2], get_cold_walker=mcmcmc._Chain.get_cold_walker, cold_heat=0.1)
assert chain.get_cold_walker(chain) == walker1
chain.walkers = [walker2, walker1]
assert chain.get_cold_walker(chain) == walker1
开发者ID:biologyguy,项目名称:RD-MCL,代码行数:9,代码来源:test_mcmcmc.py
示例13: test_chain_get_ice_walker
def test_chain_get_ice_walker():
walker1 = SimpleNamespace(ice=False)
walker2 = SimpleNamespace(ice=False)
ice_walker = SimpleNamespace(ice=True)
chain = SimpleNamespace(walkers=[walker1, walker2], get_ice_walker=mcmcmc._Chain.get_ice_walker)
assert chain.get_ice_walker(chain) is False
chain.walkers = [walker2, ice_walker, walker1]
assert chain.get_ice_walker(chain) == ice_walker
开发者ID:biologyguy,项目名称:RD-MCL,代码行数:10,代码来源:test_mcmcmc.py
示例14: parse_syllabus
def parse_syllabus(syllabus_file, content_folder='', parse_all=False):
# loading raw syllabus
syll = split_into_units(syllabus_file)[0]
cell = syll.cells[1]
def section_to_name_date(line):
name = re.findall('\*\*(.*)\*\*', line)[0]
date = release_dates.get(name)
return name, date
def subs_to_name_file(line):
try:
file_name = re.findall(r'\((.+?\.ipynb)\)', line)[0]
except IndexError:
return
subsection_name = re.findall(r'\[(.+?)\]', line)[0]
return subsection_name, file_name
is_section = lambda line: line.startswith('*')
lines = cell['source'].split('\n')
sections = [section_to_name_date(line) for line in lines
if is_section(line)]
# Make a list of lines in each section.
subsections = (tuple(g) for k, g in groupby(lines, key=lambda x: not
is_section(x)) if k)
# Filter the actual subsections.
subsections = [[subs_to_name_file(i) for i in j if subs_to_name_file(i) is
not None] for j in subsections]
data = SimpleNamespace(category='main', chapters=[])
for i, section in enumerate(zip(sections, subsections)):
if not parse_all:
# Don't convert sections with no release date.
if section[0][1] is None:
continue
# creating chapter
chapter = SimpleNamespace(category='chapter', sequentials=[])
chapter.name = section[0][0]
chapter.date = section[0][1]
chapter.url = "sec_{0}".format(str(i).zfill(2))
for j, subsection in enumerate(section[1]):
# creating sequential
sequential = SimpleNamespace(category='sequential', verticals=[])
sequential.name = subsection[0]
sequential.date = chapter.date
sequential.url = "subsec_{0}_{1}".format(str(i).zfill(2),
str(j).zfill(2))
sequential.source_notebook = content_folder + '/' + subsection[1]
chapter.sequentials.append(sequential)
data.chapters.append(chapter)
return data
开发者ID:Huaguiyuan,项目名称:phys_codes,代码行数:59,代码来源:converter.py
示例15: test_mcmcmc_mc_step_run
def test_mcmcmc_mc_step_run():
tmp_file = br.TempFile()
walker = SimpleNamespace(function=lambda func_args: 1234, params=[], proposed_score_file=tmp_file)
mcmcmc.MCMCMC.mc_step_run(walker, ["foo"])
assert tmp_file.read() == "1234"
tmp_file.clear()
walker.params = ["bar", "baz"]
walker.function = lambda func_args, params: 4321
mcmcmc.MCMCMC.mc_step_run(walker, ["foo"])
assert tmp_file.read() == "4321"
开发者ID:biologyguy,项目名称:RD-MCL,代码行数:11,代码来源:test_mcmcmc.py
示例16: test_populate_rootfs_contents_from_filesystem
def test_populate_rootfs_contents_from_filesystem(self):
with ExitStack() as resources:
workdir = resources.enter_context(TemporaryDirectory())
args = SimpleNamespace(
project=None,
suite='xenial',
arch='amd64',
image_format='img',
workdir=workdir,
output=None,
subproject=None,
subarch=None,
output_dir=None,
cloud_init=None,
with_proposed=None,
extra_ppas=None,
hooks_directory=[],
gadget_tree=self.gadget_tree,
filesystem=None,
)
state = resources.enter_context(XXXClassicBuilder(args))
# Now we have to craft enough of gadget definition to drive the
# method under test.
part = SimpleNamespace(
role=StructureRole.system_data,
filesystem_label='writable',
filesystem=FileSystemType.none,
)
volume = SimpleNamespace(
structures=[part],
bootloader=BootLoader.grub,
schema=VolumeSchema.gpt,
)
state.gadget = SimpleNamespace(
volumes=dict(volume1=volume),
)
prep_state(state, workdir)
# Fake some state expected by the method under test.
args.filesystem = resources.enter_context(TemporaryDirectory())
etc_path = os.path.join(args.filesystem, 'etc')
os.makedirs(etc_path)
with open(os.path.join(etc_path, 'fstab'), 'w') as fp:
fp.write('LABEL=cloudimg-rootfs / ext4 defaults 0 0')
state.rootfs = resources.enter_context(TemporaryDirectory())
# Jump right to the state method we're trying to test.
state._next.pop()
state._next.append(state.populate_rootfs_contents)
next(state)
# The seed metadata should exist.
# And the filesystem label should be modified to 'writable'
fstab_data = os.path.join(state.rootfs, 'etc', 'fstab')
with open(fstab_data, 'r', encoding='utf-8') as fp:
self.assertEqual(fp.read(), 'LABEL=writable '
'/ ext4 defaults 0 0')
开发者ID:CanonicalLtd,项目名称:ubuntu-image,代码行数:54,代码来源:test_classic_builder.py
示例17: test_chain_write_sample
def test_chain_write_sample():
foo_var = SimpleNamespace(draw_random=lambda: True, draw_value=0.1, name="foo", current_value=0.15)
bar_var = SimpleNamespace(draw_random=lambda: True, draw_value=0.5, name="bar", current_value=0.51)
walker1 = SimpleNamespace(variables=[foo_var, bar_var], lava=False, ice=False, current_score=35,
heat=0.1)
tmp_file = br.TempFile()
chain = SimpleNamespace(step_counter=2, get_cold_walker=lambda *_: walker1, outfile=tmp_file.path,
write_sample=mcmcmc._Chain.write_sample)
chain.write_sample(chain)
assert tmp_file.read() == "2\t0.15\t0.51\t35\n", print(tmp_file.read())
开发者ID:biologyguy,项目名称:RD-MCL,代码行数:12,代码来源:test_mcmcmc.py
示例18: _setup_fake_gpool
def _setup_fake_gpool(
frame_size, intrinsics, detection_mapping_mode, rec_dir, min_calibration_confidence
):
cap = SimpleNamespace()
cap.frame_size = frame_size
cap.intrinsics = intrinsics
pool = SimpleNamespace()
pool.capture = cap
pool.get_timestamp = time
pool.detection_mapping_mode = detection_mapping_mode
pool.min_calibration_confidence = min_calibration_confidence
pool.rec_dir = rec_dir
pool.app = "player"
return pool
开发者ID:pupil-labs,项目名称:pupil,代码行数:14,代码来源:create_calibration.py
示例19: test_chain_get_results
def test_chain_get_results():
tmp_file = br.TempFile()
tmp_file.write("""rec_id1,rec_id2,r_square
BOL-PanxαB,Bab-PanxαA,0.016894041431
BOL-PanxαB,Bch-PanxαA,0.087311057754
BOL-PanxαB,Bfo-PanxαE,0.274041115357""")
chain = SimpleNamespace(outfile=tmp_file.path, get_results=mcmcmc._Chain.get_results)
assert type(chain.get_results(chain)) == pd.DataFrame
assert str(chain.get_results(chain)) == """\
rec_id1 rec_id2 r_square
0 BOL-PanxαB Bab-PanxαA 0.016894041431
1 BOL-PanxαB Bch-PanxαA 0.087311057754
2 BOL-PanxαB Bfo-PanxαE 0.274041115357""", print(chain.get_results(chain))
开发者ID:biologyguy,项目名称:RD-MCL,代码行数:14,代码来源:test_mcmcmc.py
示例20: test_mcmcmc_reset_params
def test_mcmcmc_reset_params():
walker1 = SimpleNamespace(params=[1, 2])
walker2 = SimpleNamespace(params=[3, 4])
walker3 = SimpleNamespace(params=[5, 6])
walker4 = SimpleNamespace(params=[7, 8])
chain1 = SimpleNamespace(walkers=[walker1, walker2])
chain2 = SimpleNamespace(walkers=[walker3, walker4])
mc_obj = SimpleNamespace(reset_params=mcmcmc.MCMCMC.reset_params, chains=[chain1, chain2])
with pytest.raises(AttributeError) as e:
mc_obj.reset_params(mc_obj, ['a', 'b', 'c'])
assert "Incorrect number of params supplied in reset_params(). 2 expected; 3 supplied; ['a', 'b', 'c']" in str(e)
mc_obj.reset_params(mc_obj, ['a', 'b'])
assert walker2.params == ['a', 'b']
开发者ID:biologyguy,项目名称:RD-MCL,代码行数:16,代码来源:test_mcmcmc.py
注:本文中的types.SimpleNamespace类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论