def test_constructor(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) # mysel = {} cv = Converter1to2() self.assertTrue(isinstance(cv, ConverterXtoY)) self.myAssertDict( cv.names, { "AutomaticComponentGroup": "ComponentPreselection", "AutomaticDataSources": "PreselectedDataSources", "ComponentGroup": "ComponentSelection", "DataSourceGroup": "DataSourceSelection", "DataRecord": "UserData", "HiddenElements": "UnplottedComponents", "DynamicLinks": "DefaultDynamicLinks", "DynamicPath": "DefaultDynamicPath" }) self.myAssertDict( cv.pnames, { "Labels": "label", "LabelPaths": "nexus_path", "LabelLinks": "link", "LabelTypes": "data_type", "LabelShapes": "shape", })
def test_convert_names_pnames(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) mysel = {} cv = Converter1to2() pnames = dict(cv.pnames) names = dict(cv.names) cv.convert(mysel) self.assertEqual(mysel, {'ChannelProperties': '{}'}) for i in range(200): mysel = {} keys0 = self.__rnd.sample( list(pnames.keys()), self.__rnd.randint(0, len(list(pnames.keys())))) keys1 = self.__rnd.sample( list(names.keys()), self.__rnd.randint(0, len(list(names.keys())))) keys2 = set([self.getRandomName(20) for _ in range(2)]) for k in keys2: if k in pnames.keys() or k in names.keys() or \ k in pnames.values() or k in names.values(): keys2.remove(k) keys2.update(keys0) keys2.update(keys1) for k in keys2: if k in pnames: mysel[k] = json.dumps( dict((self.getRandomName(20), self.getRandomName(20)) for _ in range(self.__rnd.randint(1, 20)))) else: mysel[k] = self.getRandomName(20) osel = dict(mysel) cv.convert(mysel) res = {} prop = {} for k, vl in osel.items(): if k in pnames: prop[pnames[k]] = json.loads(vl) elif k in names: res[names[k]] = vl else: res[k] = vl res['ChannelProperties'] = json.dumps(prop) self.maxDiff = None self.myAssertJSONDict(mysel, res)
def test_convert_names(self): fun = sys._getframe().f_code.co_name print("Run: %s.%s() " % (self.__class__.__name__, fun)) mysel = {} cv = Converter1to2() cv.names = {} cv.pnames = {} cv.convert(mysel) self.assertEqual(mysel, {'ChannelProperties': '{}'}) for i in range(1000): mysel = {} tnames = dict((self.getRandomName(20), self.getRandomName(20)) for _ in range(self.__rnd.randint(1, 20))) for k in list(tnames.keys()): if k in list(tnames.values()): tnames.pop(k) names = {} for k, vl in tnames.items(): names[vl] = k cv.names = dict(names) keys1 = self.__rnd.sample( list(names.keys()), self.__rnd.randint(0, len(list(names.keys())))) keys2 = set([self.getRandomName(20) for _ in range(5)]) keys2.update(keys1) for k in keys2: mysel[k] = self.getRandomName(20) for k in list(mysel.keys()): if k in names.values(): mysel.pop(k) keys2.remove(k) osel = dict(mysel) cv.convert(mysel) res = {} for k, vl in osel.items(): if k in names: res[names[k]] = vl else: res[k] = vl res['ChannelProperties'] = "{}" self.myAssertDict(mysel, res)