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[:] = []