def testSignalNotInFolder(self): signal = 'XXX-269' try: loadDataFrom(signal, 'Signals') self.fail('OSError not raised') except OSError as err: self.assertTrue(signal in str(err))
def loadMultiple(signalNames, folderName, maxCount): sig_dictionary = {} folder_path = folderName + "/*" sig_files = glob.glob(folder_path) for sig in signalNames: #if(sig not in sig_files): //Why would this method not work??? #sig_dictionary = _make_dictionary(sig_dictionary, sig, None) if (not (moduleTasks.isOK(sig))): sig_dictionary = _make_dictionary(sig_dictionary, sig, None) else: try: test_tup = moduleTasks.loadDataFrom(sig, folderName) except: sig_dictionary = _make_dictionary(sig_dictionary, sig, None) else: sig_val_list = test_tup[0] sig_non_float_cnt = test_tup[1] if (sig_non_float_cnt <= maxCount): sig_dictionary = _make_dictionary(sig_dictionary, sig, sig_val_list) else: emp_list = [] sig_dictionary = _make_dictionary(sig_dictionary, sig, emp_list) return sig_dictionary
def loadMultiple(signalNames, folderName, maxCount): final = {} for signal in signalNames: try: t = mT.loadDataFrom(signal, folderName) if t[1] <= maxCount: final[signal] = t[0] else: final[signal] = [] except: final[signal] = None return final
def loadMultiple(signalNames, folderName, maxCount): dic = {} for k in signalNames: try: lists, fl = moduleTasks.loadDataFrom(k, folderName) if fl <= maxCount: dic[k] = lists else: dic[k] = [] except: dic[k] = None return dic
def testLoadMultiple(self): # Write two signal files data = ['xx3kekj', '32.238', '-0.2348', 'fej3kjskjf', '23.382'] signal1 = 'NIC-111' path1 = 'Signals/{}.txt'.format(signal1) with open(path1, 'w') as f: f.write('\n'.join(data)) data = [ 'xx3kekj', 'tiffany', 'kusholIsAWhore', 'fej3kjskjf', '3l2kjf', ] signal2 = 'TIF-111' path2 = 'Signals/{}.txt'.format(signal2) with open(path2, 'w') as f: f.write('\n'.join(data)) floats1 = loadDataFrom(signal1, 'Signals')[0] floats2 = loadDataFrom(signal2, 'Signals')[0] # Both accepted signals = loadMultiple([signal1, signal2], 'Signals', 5) self.assertEqual(signals[signal1], floats1) self.assertEqual(signals[signal2], floats2) # Both rejected signals = loadMultiple([signal1, signal2], 'Signals', 1) self.assertEqual(signals[signal1], []) self.assertEqual(signals[signal2], []) # Only one accepted signals = loadMultiple([signal1, signal2], 'Signals', 2) self.assertEqual(signals[signal1], floats1) self.assertEqual(signals[signal2], []) os.remove(path1) os.remove(path2)
def loadMultiple(signalNames, folderName, maxCount): dict = {} for signalName in signalNames: try: singal, nfc = moduleTasks.loadDataFrom(signalName, folderName) except: dict[signalName] = None continue if nfc <= maxCount: dict[signalName] = singal else: dict[signalName] = [] return dict
def loadMultiple(signalNames, folderName, maxCount): signalValueDict = {} for signalName in signalNames: try: data = moduleTasks.loadDataFrom(signalName, folderName) except: signalValueDict[signalName] = None else: valid, invalid = data if invalid <= maxCount: signalValueDict[signalName] = valid else: signalValueDict[signalName] = [] return signalValueDict
def testValidSignalDataNoFloats(self): data = ['xx3kekj', 'tiffany', 'kusholIsAWhore', 'fej3kjskjf', '3l2kjf'] signal = 'IOP-382' path = 'Signals/{}.txt'.format(signal) with open(path, 'w') as f: f.write('\n'.join(data)) floats, count_invalid = loadDataFrom(signal, 'Signals') self.assertEqual(floats, []) self.assertEqual(count_invalid, 5) os.remove(path)
def loadMultiple(signalNames, folderName, maxCount): d = {} for signalName in signalNames: try: list_vals, num_non_vals = moduleTasks.loadDataFrom( signalName, folderName) except (OSError, ValueError): d[signalName] = None else: if num_non_vals <= maxCount: d[signalName] = list_vals else: d[signalName] = [] return d
def testValidSignalData(self): # Create data file data = [ '-5.803', '3.539', 'x99ueb2', '4.903', '5.186', '-4.729', '8nqh7o0', '-4.761', '3.059', '3.617', '3jkj', 'ksk33' ] signal = 'JFJ-832' path = 'Signals/{}.txt'.format(signal) with open(path, 'w') as f: f.write('\n'.join(data)) floats, count_invalid = loadDataFrom(signal, 'Signals') self.assertEqual( floats, [-5.803, 3.539, 4.903, 5.186, -4.729, -4.761, 3.059, 3.617]) self.assertEqual(count_invalid, 4) os.remove(path)
def testInvalidSignal(self): try: loadDataFrom('badsignalname', '') self.fail('ValueError not raised') except ValueError as err: self.assertEqual(str(err), 'badsignalname is invalid.')