def test_2_components_uses(): palette = Palette(one=Sample1, two=Sample2) uses = palette.uses() uses.sort() assert_list_equal( ['air__temperature', 'deposition__rate', 'surface__elevation'], uses)
def test_2_components_provides(): palette = Palette(one=Sample1, two=Sample2) provides = palette.provides() provides.sort() assert ["air__temperature", "deposition__rate", "surface__elevation"] == provides
def test_find_providers(self): palette = Palette(sample=Sample1) providers = palette.find_provider('air__temperature') self.assertEqual(providers, []) providers = palette.find_provider('deposition__rate') self.assertEqual(providers, ['sample'])
def test_1_component_find_providers(): palette = Palette(sample=Sample1) providers = palette.find_provider("air__temperature") assert providers == [] providers = palette.find_provider("deposition__rate") assert providers == ["sample"]
def test_1_component_find_providers(): palette = Palette(sample=Sample1) providers = palette.find_provider('air__temperature') assert_equal(providers, []) providers = palette.find_provider('deposition__rate') assert_equal(providers, ['sample'])
def test_2_components_find_connections(): palette = Palette(one=Sample1, two=Sample2) connections = { "one": {"deposition__rate": ["two"]}, "two": {"air__temperature": ["one"], "surface__elevation": ["one"]}, } assert connections == palette.find_connections()
def test_2_components_find_providers(): palette = Palette(one=Sample1, two=Sample2) providers = palette.find_provider('air__temperature') assert_list_equal(['two'], providers) providers = palette.find_provider('deposition__rate') assert_equal(['one'], providers)
def test_2_components_provides(): palette = Palette(one=Sample1, two=Sample2) provides = palette.provides() provides.sort() assert_list_equal(['air__temperature', 'deposition__rate', 'surface__elevation'], provides)
def test_provides(self): palette = Palette(one=Sample1, two=Sample2) provides = palette.provides() provides.sort() self.assertListEqual( ['air__temperature', 'deposition__rate', 'surface__elevation'], provides)
def test_provides(self): palette = Palette(one=Sample1, two=Sample2) provides = palette.provides() provides.sort() self.assertListEqual(['air__temperature', 'deposition__rate', 'surface__elevation'], provides)
def test_find_providers(self): palette = Palette(one=Sample1, two=Sample2) providers = palette.find_provider('air__temperature') self.assertListEqual(['two'], providers) providers = palette.find_provider('deposition__rate') self.assertEqual(['one'], providers)
def test_2_components_find_providers(): palette = Palette(one=Sample1, two=Sample2) providers = palette.find_provider("air__temperature") assert ["two"] == providers providers = palette.find_provider("deposition__rate") assert ["one"] == providers
def test_find_connections(self): palette = Palette(one=Sample1, two=Sample2) connections = { 'one': {'deposition__rate': ['two']}, 'two': {'air__temperature': ['one'], 'surface__elevation': ['one']}, } self.assertDictEqual(connections, palette.find_connections())
def test_2_components_find_connections(): palette = Palette(one=Sample1, two=Sample2) connections = { 'one': {'deposition__rate': ['two']}, 'two': {'air__temperature': ['one'], 'surface__elevation': ['one']}, } assert_dict_equal(connections, palette.find_connections())
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_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_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_find_connections(self): palette = Palette(one=Sample1, two=Sample2) connections = { 'one': { 'deposition__rate': ['two'] }, 'two': { 'air__temperature': ['one'], 'surface__elevation': ['one'] }, } self.assertDictEqual(connections, palette.find_connections())
def test_2_components_find_connections(): palette = Palette(one=Sample1, two=Sample2) connections = { "one": { "deposition__rate": ["two"] }, "two": { "air__temperature": ["one"], "surface__elevation": ["one"] }, } assert connections == palette.find_connections()
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]
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_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_provides(self): palette = Palette(sample=Sample1) provides = palette.provides() provides.sort() self.assertEqual(['deposition__rate'], provides)
def test_uses(self): palette = Palette(sample=Sample1) uses = palette.uses() uses.sort() self.assertEqual(['air__temperature', 'surface__elevation'], uses)
def test_list(self): palette = Palette(sample=Sample1) self.assertEqual(['sample'], palette.list())
def test_create(self): palette = Palette(sample=Sample1) self.assertEqual(len(palette), 1)
def test_find_connections(self): palette = Palette(sample=Sample1) with self.assertRaises(NoProvidersError): connections = palette.find_connections()
def test_create(self): palette = Palette(one=Sample1, two=Sample2) self.assertEqual(len(palette), 2)
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())
def test_find_users(self): palette = Palette(sample=Sample1) users = palette.find_user('air__temperature') self.assertEqual(users, ['sample'])
def test_1_component_find_users(): palette = Palette(sample=Sample1) users = palette.find_user('air__temperature') assert_equal(users, ['sample'])
def test_1_component_provides(): palette = Palette(sample=Sample1) provides = palette.provides() provides.sort() assert_equal(['deposition__rate'], provides)
def test_1_component_uses(): palette = Palette(sample=Sample1) uses = palette.uses() uses.sort() assert_equal(['air__temperature', 'surface__elevation'], uses)
def test_1_component_list(): palette = Palette(sample=Sample1) assert_equal(['sample'], palette.list())
def test_find_users(self): palette = Palette(one=Sample1, two=Sample2) users = palette.find_user('air__temperature') self.assertListEqual(['one'], users)
def test_2_components_find_users(): palette = Palette(one=Sample1, two=Sample2) users = palette.find_user('air__temperature') assert_list_equal(['one'], users)
def __init__(self): self._palette = Palette(**load_landlab_components()) self._arena = Arena()
def test_2_components_list(): palette = Palette(one=Sample1, two=Sample2) list = palette.list() list.sort() assert_list_equal(['one', 'two'], list)