本文整理汇总了Python中types.SimpleNamespace类的典型用法代码示例。如果您正苦于以下问题:Python SimpleNamespace类的具体用法?Python SimpleNamespace怎么用?Python SimpleNamespace使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimpleNamespace类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
)
示例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()
示例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
示例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
示例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)
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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
示例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"