Example #1
0
    def test_escapeChars(self):
        ref = r"b['a\n.b\\'].x"
        cuid = ComponentUID(ref)
        self.assertEqual(cuid._cids, (('b', ('a\n.b\\', )), ('x', tuple())))

        m = ConcreteModel()
        m.b = Block(['a\n.b\\'])
        m.b['a\n.b\\'].x = x = Var()
        self.assertTrue(cuid.matches(x))
        self.assertEqual(repr(ComponentUID(x)), ref)
        self.assertEqual(str(ComponentUID(x)), r"b['a\n.b\\'].x")
Example #2
0
    def test_nonIntNumber(self):
        inf = float('inf')
        m = ConcreteModel()
        m.b = Block([inf, 'inf'])

        m.b[inf].x = x = Var()
        ref = r"b[inf].x"

        cuid = ComponentUID(x)
        self.assertEqual(cuid._cids, (('b', (inf, )), ('x', tuple())))

        self.assertTrue(cuid.matches(x))
        self.assertEqual(repr(ComponentUID(x)), ref)
        self.assertEqual(str(ComponentUID(x)), ref)

        cuid = ComponentUID(ref)
        self.assertEqual(cuid._cids, (('b', (inf, )), ('x', tuple())))

        self.assertTrue(cuid.matches(x))
        self.assertEqual(repr(ComponentUID(x)), ref)
        self.assertEqual(str(ComponentUID(x)), ref)

        ref = r"b:#inf.x"
        cuid = ComponentUID(ref)
        self.assertEqual(cuid._cids, (('b', (inf, )), ('x', tuple())))

        self.assertTrue(cuid.matches(x))
        self.assertEqual(ComponentUID(x).get_repr(1), ref)
        self.assertEqual(str(ComponentUID(x)), r"b[inf].x")

        #
        m.b['inf'].x = x = Var()
        ref = r"b['inf'].x"
        #

        cuid = ComponentUID(x)
        self.assertEqual(cuid._cids, (('b', ('inf', )), ('x', tuple())))

        self.assertTrue(cuid.matches(x))
        self.assertEqual(repr(ComponentUID(x)), ref)
        self.assertEqual(str(ComponentUID(x)), ref)

        cuid = ComponentUID(ref)
        self.assertEqual(cuid._cids, (('b', ('inf', )), ('x', tuple())))

        self.assertTrue(cuid.matches(x))
        self.assertEqual(repr(ComponentUID(x)), ref)
        self.assertEqual(str(ComponentUID(x)), ref)

        ref = r"b:$inf.x"
        cuid = ComponentUID(ref)
        self.assertEqual(cuid._cids, (('b', ('inf', )), ('x', tuple())))

        self.assertTrue(cuid.matches(x))
        self.assertEqual(ComponentUID(x).get_repr(1), ref)
        self.assertEqual(str(ComponentUID(x)), r"b['inf'].x")
Example #3
0
 def test_matches_ellipsis4(self):
     cuid = ComponentUID('b[**,1,*].c')
     self.assertTrue(cuid.matches(self.m.b[1, 1].c))
     self.assertTrue(cuid.matches(self.m.b[1, '2'].c))
Example #4
0
 def test_matches_ellipsis3(self):
     cuid = ComponentUID('b[**,1,1,3].c')
     self.assertFalse(cuid.matches(self.m.b[1, 1].c))
     self.assertFalse(cuid.matches(self.m.b[1, '2'].c))
Example #5
0
 def test_matches_mismatch_3(self):
     cuid = ComponentUID('b:*,*,*.c.a:*')
     self.assertFalse(cuid.matches(self.m.b[1, '2'].c.a[3]))
     self.assertFalse(cuid.matches(self.m.b[1, '2'].c.a['2']))
Example #6
0
 def test_matches_mismatch_name(self):
     cuid = ComponentUID('b:*,*.d')
     self.assertFalse(cuid.matches(self.m.b[1, '2'].c))
     self.assertFalse(cuid.matches(self.m.b[1, '2'].c))
Example #7
0
 def test_matches_wildcard_2(self):
     cuid = ComponentUID('b:*,*.c.a:**')
     self.assertTrue(cuid.matches(self.m.b[1, '2'].c.a[3]))
     self.assertTrue(cuid.matches(self.m.b[1, '2'].c.a['2']))
Example #8
0
 def test_matches_explicit_2(self):
     cuid = ComponentUID('b:#1,#2.c.a:#3')
     self.assertFalse(cuid.matches(self.m.b[1, '2'].c.a[3]))
     self.assertFalse(cuid.matches(self.m.b[1, '2'].c.a['2']))
Example #9
0
 def test_matches_explicit(self):
     cuid = ComponentUID(self.m.b[1, '2'].c.a[3])
     self.assertTrue(cuid.matches(self.m.b[1, '2'].c.a[3]))
     self.assertFalse(cuid.matches(self.m.b[1, '2'].c.a['2']))