def test_get(self): smap = SymbolMap() labeler = TextLabeler() self.assertEqual('x', smap.getSymbol(self.instance.x, labeler)) self.assertEqual('y(1)', smap.getSymbol(self.instance.y[1], labeler)) self.assertEqual(set(smap.bySymbol.keys()), set(['x', 'y(1)'])) self.assertEqual('x', smap.getSymbol(self.instance.x, labeler))
def test_creates(self): smap = SymbolMap() labeler = TextLabeler() smap.createSymbols(self.instance.component_data_objects(Var), labeler) self.assertEqual( set(smap.bySymbol.keys()), set([ 'x', 'y(1)', 'y(2)', 'y(3)', 'b_x', 'b_y(1)', 'b_y(2)', 'b_y(3)' ]))
def test_adds(self): smap = SymbolMap() labeler = TextLabeler() smap.addSymbols((obj, labeler(obj)) for obj in self.instance.component_data_objects(Var)) self.assertEqual( set(smap.bySymbol.keys()), set([ 'x', 'y(1)', 'y(2)', 'y(3)', 'b_x', 'b_y(1)', 'b_y(2)', 'b_y(3)' ]))
def test_error2(self): smap = SymbolMap() smap.addSymbol(self.instance.x, 'x') smap.alias(self.instance.x, 'X') self.assertEqual(id(smap.getObject('x')), id(self.instance.x)) self.assertEqual(id(smap.getObject('X')), id(self.instance.x)) self.assertEqual(id(smap.getObject('y')), id(SymbolMap.UnknownSymbol))
def test_error1(self): smap = SymbolMap() labeler = TextLabeler() self.assertEqual('x', smap.getSymbol(self.instance.x, labeler)) class FOO(object): def __call__(self, *args): return 'x' labeler = FOO() try: self.assertEqual('x', smap.getSymbol(self.instance.y[1], labeler)) self.fail("Expected RuntimeError") except RuntimeError: pass
def test_alias_and_getObject(self): smap = SymbolMap() smap.addSymbol(self.instance.x, 'x') smap.alias(self.instance.x, 'X') self.assertEqual(set(smap.bySymbol.keys()), set(['x'])) self.assertEqual(set(smap.aliases.keys()), set(['X'])) self.assertEqual(id(smap.getObject('x')), id(self.instance.x)) self.assertEqual(id(smap.getObject('X')), id(self.instance.x))
def test_create(self): smap = SymbolMap() labeler = TextLabeler() smap.createSymbol(self.instance.x, labeler) smap.createSymbol(self.instance.y[1], labeler) self.assertEqual(set(smap.bySymbol.keys()), set(['x', 'y(1)']))
def test_add(self): smap = SymbolMap() smap.addSymbol(self.instance.x, "x") smap.addSymbol(self.instance.y[1], "y[1]") self.assertEqual(set(smap.bySymbol.keys()), set(['x', 'y[1]']))