def test_merge_regxs(self): pm1 = Pmod( _alias="pm1", _regxs=[ ("e", Pmod(_alias="E")), ("a", Pmod(_alias="A")), ("c", Pmod(_alias="C")), ], ) pm2 = Pmod( _alias="pm2", _regxs=[ ("b", Pmod(_alias="B")), ("a", Pmod(_alias="AA")), ("d", Pmod(_alias="DD")), ], ) pm = pm1._merge(pm2) self.assertSequenceEqual(pmod2regexstrs(pm), list("ecbad")) self.assertEqual(pm._regxs[re.compile("a")]._alias, "AA") self.assertSequenceEqual(pmod2regexstrs(pm1), list("eac")) self.assertSequenceEqual(pmod2regexstrs(pm2), list("bad")) self.assertEqual(pm._steps, {}) self.assertEqual(pm1._steps, {}) self.assertEqual(pm2._steps, {}) pm = pm2._merge(pm1) self.assertSequenceEqual(pmod2regexstrs(pm), list("bdeac")) self.assertEqual(pm._regxs[re.compile("a")]._alias, "A") self.assertSequenceEqual(pmod2regexstrs(pm1), list("eac")) self.assertSequenceEqual(pmod2regexstrs(pm2), list("bad")) self.assertEqual(pm._steps, {}) self.assertEqual(pm1._steps, {}) self.assertEqual(pm2._steps, {})
def test_merge_regxs(self): pm1 = Pmod(_alias='pm1', _regxs=[ ('e', Pmod(_alias='E')), ('a', Pmod(_alias='A')), ('c', Pmod(_alias='C'))]) pm2 = Pmod(_alias='pm2', _regxs=[ ('b', Pmod(_alias='B')), ('a', Pmod(_alias='AA')), ('d', Pmod(_alias='DD')), ]) pm = pm1._merge(pm2) self.assertSequenceEqual(pmod2regexstrs(pm), list('ecbad')) self.assertEqual(pm._regxs[re.compile('a')]._alias, 'AA') self.assertSequenceEqual(pmod2regexstrs(pm1), list('eac')) self.assertSequenceEqual(pmod2regexstrs(pm2), list('bad')) self.assertEqual(pm._steps, {}) self.assertEqual(pm1._steps, {}) self.assertEqual(pm2._steps, {}) pm = pm2._merge(pm1) self.assertSequenceEqual(pmod2regexstrs(pm), list('bdeac')) self.assertEqual(pm._regxs[re.compile('a')]._alias, 'A') self.assertSequenceEqual(pmod2regexstrs(pm1), list('eac')) self.assertSequenceEqual(pmod2regexstrs(pm2), list('bad')) self.assertEqual(pm._steps, {}) self.assertEqual(pm1._steps, {}) self.assertEqual(pm2._steps, {})
def test_merge_name_recurse(self): pm1 = Pmod(_alias='pm1', _steps={'a': Pmod(_alias='R1')}) pm2 = Pmod(_alias='pm2', _steps={'a': Pmod(_alias='R2'), 'b': Pmod(_alias='R22')}) pm = pm1._merge(pm2) self.assertEqual(pm._steps['a']._alias, 'R2') self.assertEqual(pm1._steps['a']._alias, 'R1') self.assertEqual(pm2._steps['a']._alias, 'R2') self.assertEqual(len(pm1._steps), 1) self.assertEqual(len(pm2._steps), 2) pm = pm2._merge(pm1) self.assertEqual(pm._steps['a']._alias, 'R1') self.assertEqual(pm1._steps['a']._alias, 'R1') self.assertEqual(pm2._steps['a']._alias, 'R2') self.assertEqual(len(pm1._steps), 1) self.assertEqual(len(pm2._steps), 2)
def test_merge_name_recurse(self): pm1 = Pmod(_alias="pm1", _steps={"a": Pmod(_alias="R1")}) pm2 = Pmod( _alias="pm2", _steps={"a": Pmod(_alias="R2"), "b": Pmod(_alias="R22")} ) pm = pm1._merge(pm2) self.assertEqual(pm._steps["a"]._alias, "R2") self.assertEqual(pm1._steps["a"]._alias, "R1") self.assertEqual(pm2._steps["a"]._alias, "R2") self.assertEqual(len(pm1._steps), 1) self.assertEqual(len(pm2._steps), 2) pm = pm2._merge(pm1) self.assertEqual(pm._steps["a"]._alias, "R1") self.assertEqual(pm1._steps["a"]._alias, "R1") self.assertEqual(pm2._steps["a"]._alias, "R2") self.assertEqual(len(pm1._steps), 1) self.assertEqual(len(pm2._steps), 2)
def test_merge_steps(self): pm1 = Pmod(_alias="pm1", _steps={"a": Pmod(_alias="A"), "c": Pmod(_alias="C")}) pm2 = Pmod( _alias="pm2", _steps={ "b": Pmod(_alias="B"), "a": Pmod(_alias="AA"), "d": Pmod(_alias="DD"), }, ) pm = pm1._merge(pm2) self.assertEqual(sorted(pm._steps.keys()), list("abcd")) pm = pm2._merge(pm1) self.assertEqual(sorted(pm._steps.keys()), list("abcd")) self.assertEqual(len(pm1._steps), 2) self.assertEqual(len(pm2._steps), 3) pm1 = Pmod(_steps={"a": Pmod(_alias="A"), "c": Pmod(_alias="C")}) pm2 = Pmod( _alias="pm2", _steps={ "b": Pmod(_alias="B"), "a": Pmod(_alias="AA"), "d": Pmod(_alias="DD"), }, ) pm = pm1._merge(pm2) self.assertEqual(sorted(pm._steps.keys()), list("abcd")) self.assertEqual(pm._steps["a"]._alias, "AA") self.assertEqual(len(pm1._steps), 2) self.assertEqual(len(pm2._steps), 3) self.assertEqual(pm._regxs, {}) self.assertEqual(pm1._regxs, {}) self.assertEqual(pm2._regxs, {}) pm = pm2._merge(pm1) self.assertEqual(sorted(pm._steps.keys()), list("abcd")) self.assertEqual(pm._steps["a"]._alias, "A") self.assertEqual(len(pm1._steps), 2) self.assertEqual(len(pm2._steps), 3) self.assertEqual(pm._regxs, {}) self.assertEqual(pm1._regxs, {}) self.assertEqual(pm2._regxs, {})
def test_merge_name(self): pm1 = Pmod(_alias="pm1") pm2 = Pmod(_alias="pm2") pm = pm1._merge(pm2) self.assertEqual(pm._alias, "pm2") self.assertEqual(pm1._alias, "pm1") self.assertEqual(pm2._alias, "pm2") pm = pm2._merge(pm1) self.assertEqual(pm._alias, "pm1") self.assertEqual(pm1._alias, "pm1") self.assertEqual(pm2._alias, "pm2") pm1 = Pmod() pm2 = Pmod(_alias="pm2") pm = pm1._merge(pm2) self.assertEqual(pm._alias, "pm2") self.assertEqual(pm1._alias, None) self.assertEqual(pm2._alias, "pm2") pm = pm2._merge(pm1) self.assertEqual(pm._alias, "pm2") self.assertEqual(pm1._alias, None) self.assertEqual(pm2._alias, "pm2")
def test_merge_name(self): pm1 = Pmod(_alias='pm1') pm2 = Pmod(_alias='pm2') pm = pm1._merge(pm2) self.assertEqual(pm._alias, 'pm2') self.assertEqual(pm1._alias, 'pm1') self.assertEqual(pm2._alias, 'pm2') pm = pm2._merge(pm1) self.assertEqual(pm._alias, 'pm1') self.assertEqual(pm1._alias, 'pm1') self.assertEqual(pm2._alias, 'pm2') pm1 = Pmod() pm2 = Pmod(_alias='pm2') pm = pm1._merge(pm2) self.assertEqual(pm._alias, 'pm2') self.assertEqual(pm1._alias, None) self.assertEqual(pm2._alias, 'pm2') pm = pm2._merge(pm1) self.assertEqual(pm._alias, 'pm2') self.assertEqual(pm1._alias, None) self.assertEqual(pm2._alias, 'pm2')
def test_merge_steps(self): pm1 = Pmod(_alias='pm1', _steps={'a': Pmod(_alias='A'), 'c': Pmod(_alias='C')}) pm2 = Pmod(_alias='pm2', _steps={'b': Pmod(_alias='B'), 'a': Pmod(_alias='AA'), 'd': Pmod(_alias='DD'), }) pm = pm1._merge(pm2) self.assertEqual(sorted(pm._steps.keys()), list('abcd')) pm = pm2._merge(pm1) self.assertEqual(sorted(pm._steps.keys()), list('abcd')) self.assertEqual(len(pm1._steps), 2) self.assertEqual(len(pm2._steps), 3) pm1 = Pmod(_steps={'a': Pmod(_alias='A'), 'c': Pmod(_alias='C')}) pm2 = Pmod(_alias='pm2', _steps={'b': Pmod(_alias='B'), 'a': Pmod(_alias='AA'), 'd': Pmod(_alias='DD'), }) pm = pm1._merge(pm2) self.assertEqual(sorted(pm._steps.keys()), list('abcd')) self.assertEqual(pm._steps['a']._alias, 'AA') self.assertEqual(len(pm1._steps), 2) self.assertEqual(len(pm2._steps), 3) self.assertEqual(pm._regxs, {}) self.assertEqual(pm1._regxs, {}) self.assertEqual(pm2._regxs, {}) pm = pm2._merge(pm1) self.assertEqual(sorted(pm._steps.keys()), list('abcd')) self.assertEqual(pm._steps['a']._alias, 'A') self.assertEqual(len(pm1._steps), 2) self.assertEqual(len(pm2._steps), 3) self.assertEqual(pm._regxs, {}) self.assertEqual(pm1._regxs, {}) self.assertEqual(pm2._regxs, {})