def test_1_component_dict_interface(): palette = Palette(sample=Sample1) assert_dict_equal(dict(sample=Sample1), palette) assert_equal(len(palette), 1) assert_equal(palette.keys(), ['sample']) assert_equal(palette.values(), [Sample1]) items = palette.items() assert_tuple_equal(('sample', Sample1), items[0])
def test_dict_interface(self): palette = Palette(sample=Sample1) self.assertDictEqual(dict(sample=Sample1), palette) self.assertEqual(len(palette), 1) self.assertEqual(palette.keys(), ['sample']) self.assertEqual(palette.values(), [Sample1]) items = palette.items() self.assertTupleEqual(('sample', Sample1), items[0])
def test_1_component_dict_interface(): palette = Palette(sample=Sample1) assert dict(sample=Sample1) == palette assert len(palette) == 1 assert list(palette.keys()) == ["sample"] assert list(palette.values()) == [Sample1] items = list(palette.items()) assert ("sample", Sample1) == items[0]
def test_empty_palette(): """Create a palette without components.""" palette = Palette() assert len(palette) == 0 assert list(palette.list()) == [] assert list(palette.keys()) == [] assert palette.uses() == [] assert palette.provides() == [] providers = palette.find_provider("air__temperature") assert providers == [] users = palette.find_user("air__temperature") assert users == [] connections = palette.find_connections() assert connections == {}
def test_empty_palette(): """Create a palette without components.""" palette = Palette() assert_equal(len(palette), 0) assert_equal(list(palette.list()), []) assert_equal(list(palette.keys()), []) assert_equal(palette.uses(), []) assert_equal(palette.provides(), []) providers = palette.find_provider('air__temperature') assert_equal(providers, []) users = palette.find_user('air__temperature') assert_equal(users, []) connections = palette.find_connections() assert_dict_equal(connections, {})
def test_dict_interface(self): palette = Palette(one=Sample1, two=Sample2) self.assertDictEqual(dict(one=Sample1, two=Sample2), palette) self.assertEqual(len(palette), 2) keys = palette.keys() keys.sort() self.assertListEqual(['one', 'two'], keys) values = palette.values() self.assertEqual(2, len(values)) self.assertTrue(Sample1 in values and Sample2 in values) items = palette.items() items.sort() self.assertEqual(2, len(items)) self.assertTupleEqual(('one', Sample1), items[0]) self.assertTupleEqual(('two', Sample2), items[1])
def test_2_components_dict_interface(): palette = Palette(one=Sample1, two=Sample2) assert_dict_equal(dict(one=Sample1, two=Sample2), palette) assert_equal(len(palette), 2) keys = palette.keys() keys.sort() assert_list_equal(['one', 'two'], keys) values = palette.values() assert_equal(2, len(values)) assert_true(Sample1 in values and Sample2 in values) items = palette.items() items.sort() assert_equal(2, len(items)) assert_tuple_equal(('one', Sample1), items[0]) assert_tuple_equal(('two', Sample2), items[1])
def test_2_components_dict_interface(): palette = Palette(one=Sample1, two=Sample2) assert dict(one=Sample1, two=Sample2) == palette assert len(palette) == 2 keys = list(palette.keys()) keys.sort() assert ["one", "two"] == keys values = palette.values() assert 2 == len(values) assert Sample1 in values and Sample2 in values items = list(palette.items()) items.sort() assert 2 == len(items) assert ("one", Sample1) == items[0] assert ("two", Sample2) == items[1]
class Framework(object): """ A framework for connecting and running component from The Landlab. """ def __init__(self): self._palette = Palette(**load_landlab_components()) self._arena = Arena() def instantiate(self, name): """ Instantiate a component called *name* from the palette and move it to the arena. """ try: self._arena.instantiate(self._palette.get(name), name) except KeyError: pass def remove(self, name): """ Remove a component called *name* from the arena. """ try: self._arena.remove(name) except KeyError: pass def list_palette(self): """ Get a list of names of the components in the palette. """ return self._palette.list() def list_arena(self): """ Get a list of names of the components in the arena. """ return self._arena.list() def arena_uses(self): """ Get a list of variable names that components in the arena use. """ return self._arena.uses() def arena_provides(self): """ Get a list of variable names that components in the arena provide. """ return self._arena.provides() def palette_uses(self): """ Get a list of variable names that components in the palette use. """ return self._palette.uses() def palette_provides(self): """ Get a list of variable names that components in the palette provide. """ return self._palette.provides() def __repr__(self): return 'Framework(%s)' % ', '.join(self._palette.keys())