def test_mapping(self): d = util.MappingView({'a': 1, 'b': 2}) self.assertEqual(1, d['a']) self.assertEqual(2, len(d)) self.assertEqual({'a': 1, 'b': 2}, dict(d)) self.assertIn('b', d) self.assertEqual({'a', 'b'}, set(d.keys())) self.assertEqual({1, 2}, set(d.values())) self.assertEqual({('a', 1), ('b', 2)}, set(d.items())) self.assertEqual(2, d.get('b')) self.assertEqual(3, d.get('c', 3)) self.assertEqual({'a': 1, 'b': 2}, d) self.assertNotEqual({'a': 1, 'b': 2, 'c': 3}, d) # Assert immutability with self.assertRaises(TypeError): d['c'] = 3 with self.assertRaises(TypeError): del d['b'] with self.assertRaises(AttributeError): d.pop('a') with self.assertRaises(AttributeError): d.popitem() with self.assertRaises(AttributeError): d.clear() with self.assertRaises(AttributeError): d.update({'a': 4, 'b': 5}) with self.assertRaises(AttributeError): d.setdefault('c', 3)
def container_environs(self): '''Environments associated with the different container platforms. :type: :class:`Dict[str, Environment]` ''' return utility.MappingView(self._container_environs)
def resources(self): '''The resources template strings associated with this partition. This is a dictionary, where the key is the name of a resource and the value is the scheduler options or directives associated with this resource. :type: :class:`Dict[str, List[str]]` ''' return utility.MappingView(self._resources)
def test_mapping_view(): d = util.MappingView({'a': 1, 'b': 2}) assert 1 == d['a'] assert 2 == len(d) assert {'a': 1, 'b': 2} == dict(d) assert 'b' in d assert {'a', 'b'} == set(d.keys()) assert {1, 2} == set(d.values()) assert {('a', 1), ('b', 2)} == set(d.items()) assert 2 == d.get('b') assert 3 == d.get('c', 3) assert {'a': 1, 'b': 2} == d assert d == util.MappingView({'b': 2, 'a': 1}) assert str(d) == str({'a': 1, 'b': 2}) assert {'a': 1, 'b': 2, 'c': 3} != d # Assert immutability with pytest.raises(TypeError): d['c'] = 3 with pytest.raises(TypeError): del d['b'] with pytest.raises(AttributeError): d.pop('a') with pytest.raises(AttributeError): d.popitem() with pytest.raises(AttributeError): d.clear() with pytest.raises(AttributeError): d.update({'a': 4, 'b': 5}) with pytest.raises(AttributeError): d.setdefault('c', 3)
def variables(self): """The environment variables associated with this environment. :type: dictionary of :class:`str` keys/values. """ return util.MappingView(self._variables)
def resources(self): return utility.MappingView(self._resources)
def container_environs(self): return utility.MappingView(self._container_environs)
def variables(self): '''The environment variables associated with this environment. :type: :class:`OrderedDict[str, str]` ''' return util.MappingView(self._variables)
def perfvalues(self): return util.MappingView(self._perfvalues)