本文整理汇总了Python中pyrsistent.m函数的典型用法代码示例。如果您正苦于以下问题:Python m函数的具体用法?Python m怎么用?Python m使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了m函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_supports_hash_and_equals
def test_supports_hash_and_equals():
x = m(a=1, b=2, c=3)
y = m(a=1, b=2, c=3)
assert hash(x) == hash(y)
assert x == y
assert not (x != y)
示例2: test_unordered_messages
def test_unordered_messages(self):
messages = map(
Message.new, [
m(task_uuid='foo', task_level=[2]),
m(task_uuid='foo', task_level=[1]),
])
self.assertEqual(m(foo=[messages[1], messages[0]]), to_tasks(messages))
示例3: test_single_task
def test_single_task(self):
messages = map(
Message.new, [
m(task_uuid='foo', task_level=[1]),
m(task_uuid='foo', task_level=[2]),
])
self.assertEqual(m(foo=messages), to_tasks(messages))
示例4: test_no_task_level
def test_no_task_level(self):
messages = map(
Message.new, [
m(task_uuid='foo'),
m(task_uuid='foo'),
])
self.assertEqual(m(foo=messages), to_tasks(messages))
示例5: test_not_equal
def test_not_equal():
x = m(a=1, b=2, c=3)
y = m(a=1, b=2)
assert x != y
assert not (x == y)
assert y != x
assert not (y == x)
示例6: __init__
def __init__(self, timefunc=time.time):
self.__data = m(products=m(), transactions=v(), summaries=v())
self.__event_queue = Queue() # sequential query execution
self.__lock = Condition() # passive waiting only
self.__stop = Event()
self.time = timefunc
Thread(target=self.__run).start()
示例7: test_update_with
def test_update_with():
assert m(a=1).update_with(add, m(a=2, b=4)) == m(a=3, b=4)
assert m(a=1).update_with(lambda l, r: l, m(a=2, b=4)) == m(a=1, b=4)
def map_add(l, r):
return dict(list(l.items()) + list(r.items()))
assert m(a={'c': 3}).update_with(map_add, m(a={'d': 4})) == m(a={'c': 3, 'd': 4})
示例8: test_results_writer
def test_results_writer():
"""Does the results writer output what it should?"""
results = m(episode=v(0, 1, 2), step_count=v(12, 22, 11))
output_path = os.path.join(os.getcwd(), 'results.txt')
results_descriptor = ResultsDescriptor(2, output_path, ['episode', 'step_count'])
initialize_results(results_descriptor)
write_results(results, results_descriptor)
results_check = read_results(output_path)
assert numpy.array_equal(results_check, numpy.array([[0., 12.], [1., 22.], [2., 11.]]))
new_results = m(episode=v(3), step_count=v(12.33))
write_results(new_results, results_descriptor)
new_results_check = read_results(output_path)
assert numpy.array_equal(new_results_check, numpy.array([[0., 12.], [1., 22.], [2., 11.], [3., 12.33]]))
示例9: __init__
def __init__(self, pipe = None, new_stack = None):
if not pipe:
stack = v(m())
dump = m()
else:
stack = pipe.stack
dump = pipe.dump
if new_stack:
stack = new_stack
self.stack = stack
self.dump = dump
示例10: test_multiple_tasks
def test_multiple_tasks(self):
messages = map(
Message.new, [
m(task_uuid='foo', task_level=[1]),
m(task_uuid='bar', task_level=[1]),
m(task_uuid='foo', task_level=[2]),
])
self.assertEqual(
m(
foo=[messages[0], messages[2]],
bar=[messages[1]],
),
to_tasks(messages))
示例11: test_mutant_decorator
def test_mutant_decorator():
@mutant
def fn(a_list, a_dict):
assert a_list == v(1, 2, 3)
assert isinstance(a_dict, type(m()))
assert a_dict == {'a': 5}
return [1, 2, 3], {'a': 3}
pv, pm = fn([1, 2, 3], a_dict={'a': 5})
assert pv == v(1, 2, 3)
assert pm == m(a=3)
assert isinstance(pm, type(m()))
示例12: test_various_iterations
def test_various_iterations():
assert set(['a', 'b']) == set(m(a=1, b=2))
assert ['a', 'b'] == sorted(m(a=1, b=2).keys())
assert isinstance(m().keys(), PVector)
assert set([1, 2]) == set(m(a=1, b=2).itervalues())
assert [1, 2] == sorted(m(a=1, b=2).values())
assert isinstance(m().values(), PVector)
assert set([('a', 1), ('b', 2)]) == set(m(a=1, b=2).iteritems())
assert set([('a', 1), ('b', 2)]) == set(m(a=1, b=2).items())
assert isinstance(m().items(), PVector)
示例13: start_configuration
def start_configuration():
"""
Creates the initial PMap that will be passed down the pipeline
:return:
"""
return pyr.m()
示例14: test_evolver_remove_element_not_present
def test_evolver_remove_element_not_present():
e = m(a=1000, b=2000).evolver()
with pytest.raises(KeyError) as error:
del e['c']
assert str(error.value) == "'c'"
示例15: __init__
def __init__(self, x_size, y_size, tile_size):
self.size = pyrsistent.m(x=x_size, y=y_size)
tile_types = [
tile.GrassTile,
tile.GrassTile,
tile.WaterTile,
]
self.tiles = {
vector.Vector2(x, y): random.choice(tile_types)()
for x in range(x_size)
for y in range(y_size)
}
self.sprite_batch = multimedia.SpriteBatch()
self.sprites = pyrsistent.pmap({
coord: multimedia.Sprite(
self.tiles[coord].image,
vector.Vector2(
x=coord.x*tile_size,
y=coord.y*tile_size,
),
batch=self.sprite_batch,
)
for coord in self.tiles
})