def test_constructor(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) arr = { "1.2.3": [1, 2, 3], "2.22.1": [2, 22, 1], "3.23.5": [3, 23, 5], "1.81.6": [1, 81, 6], "1.1.7": [1, 1, 7], "1.0.9": [1, 0, 9], } self.myAssertRaise(Exception, Converter, None) self.myAssertRaise(Exception, Converter, "") self.myAssertRaise(Exception, Converter, "3.4") self.myAssertRaise(Exception, Converter, "2") for k, ar in arr.items(): cv = Converter(k) self.assertEqual(cv.majorversion, ar[0]) self.assertEqual(cv.minorversion, ar[1]) self.assertEqual(cv.patchversion, ar[2]) self.assertEqual(len(cv.down), 2) self.assertEqual(len(cv.up), 2) self.assertTrue(isinstance(cv.up[0], Converter1to2)) self.assertTrue(isinstance(cv.up[1], Converter2to3)) self.assertTrue(isinstance(cv.down[1], Converter3to2)) self.assertTrue(isinstance(cv.down[0], Converter2to1))
def test_allkeys(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) histlog = [] myver = "1.2.3" cv = Converter(myver) self.assertEqual( cv.allkeys({}), set([ 'UserData', 'UnplottedComponents', 'DataSourceSelection', 'DefaultDynamicLinks', 'DataSourcePreselection', 'PreselectingDataSources', 'ComponentPreselection', 'ComponentSelection', 'DefaultDynamicPath', 'DynamicPath', 'AutomaticComponentGroup', 'DynamicLinks', 'ComponentGroup', 'HiddenElements', 'DataSourceGroup', 'AutomaticDataSources', 'DataRecord', 'PreselectedDataSources', 'InitDataSources' ])) cv.up = [] cv.down = [] self.assertEqual(cv.allkeys({}), set()) for i in range(20): lk = [] kk = self.__rnd.randint(0, 20) for k in range(kk): lk.append(MyConverter1(histlog)) lk[-1].names = dict( (self.getRandomString(20), self.getRandomString(20)) for _ in range(self.__rnd.randint(0, 20))) cv.up[:] = lk names = dict((self.getRandomString(20), self.getRandomString(20)) for _ in range(self.__rnd.randint(0, 20))) for k in list(names.keys()): if k in names.values(): names.pop(k) res = set(names.keys()) for ll in lk: res.update(set(ll.names.keys())) res.update(set(ll.names.values())) self.assertEqual(cv.allkeys(names), res)
def test_convert(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) histlog = [] myver = "1.2.3" cv = Converter(myver) cv.up = [] cv.down = [] self.myAssertRaise(Exception, cv.convert, {"Version": "11.2.3"}) mysel = {"Version": "1.0.1"} cv.convert(mysel) self.assertEqual(mysel["Version"], "1.0.1") cv.down = [ MyConverter1(histlog), MyConverter2(histlog), MyConverter3(histlog), MyConverter4(histlog) ] histlog[:] = [] mysel = {"Version": "3.23.3"} cv.convert(mysel) self.assertEqual(mysel["Version"], myver) self.assertEqual(histlog, ["MyConverter2", "MyConverter1"]) histlog[:] = [] mysel = {"Version": "1.23.3"} cv.convert(mysel) self.assertEqual(mysel["Version"], "1.23.3") self.assertEqual(histlog, []) histlog[:] = [] mysel = {"Version": "2.13.3"} cv.convert(mysel) self.assertEqual(mysel["Version"], myver) self.assertEqual(histlog, ["MyConverter1"]) histlog[:] = [] mysel = {"Version": "4.03.3"} cv.convert(mysel) self.assertEqual(mysel["Version"], myver) self.assertEqual(histlog, ["MyConverter3", "MyConverter2", "MyConverter1"]) histlog[:] = [] cv.down = [] myver = "3.2.3" cv = Converter(myver) self.myAssertRaise(Exception, cv.convert, {"Version": "11.2.3"}) cv.up = [ MyConverter1(histlog), MyConverter2(histlog), MyConverter3(histlog), MyConverter4(histlog) ] mysel = {"Version": "1.03.3"} cv.convert(mysel) self.assertEqual(mysel["Version"], myver) self.assertEqual(histlog, ["MyConverter1", "MyConverter2"]) histlog[:] = [] mysel = {"Version": "3.90.3"} cv.convert(mysel) self.assertEqual(mysel["Version"], "3.90.3") self.assertEqual(histlog, []) histlog[:] = [] mysel = {"Version": "2.0.3"} cv.convert(mysel) self.assertEqual(mysel["Version"], myver) self.assertEqual(histlog, ["MyConverter2"]) histlog[:] = []