Python check sanity
28 Python code examples are found related to "
check sanity".
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
Example 1
Source File: npi_view.py From NTP-vat-release with MIT License | 6 votes |
def trace_sanity_check(self): assert (not self.trace_stack) for p, pentry in self.all_trace.items(): num_seq = len(pentry['in_prgs']) for i in xrange(num_seq): seq_len = len(pentry['in_prgs'][i]) for j in xrange(seq_len): caller_ptr = pentry['caller_ptr'][i][j] if caller_ptr is None: continue caller_name, ci, cj = caller_ptr assert(self.all_trace[caller_name]['out_boundary_begin'][ci][cj] == pentry['in_boundary_begin'][i][j]) assert(self.all_trace[caller_name]['out_boundary_end'][ci][cj] == pentry['in_boundary_end'][i][j])
Example 2
Source File: rotate.py From pytomo3d with GNU Lesser General Public License v3.0 | 6 votes |
def check_vertical_inventory_sanity(tr, inventory): """ Check the inventory of vertical(Z) component, check if the abs(dip) is 90 and azimuth is 0. """ if tr.stats.channel[-1] != "Z": raise ValueError("Function only checks vertical(Z) component(%s)" % tr.stats.channel) dip, azi = extract_channel_orientation(tr, inventory) if dip is None or azi is None: return False if np.isclose(abs(dip), 90.0) and np.isclose(abs(azi), 0.0): return True else: return False
Example 3
Source File: pipeline.py From reframe with BSD 3-Clause "New" or "Revised" License | 6 votes |
def check_sanity(self): '''The sanity checking phase of the regression test pipeline. :raises reframe.core.exceptions.SanityError: If the sanity check fails. .. warning:: .. versionchanged:: 3.0 You may not override this method directly unless you are in special test. See `here <migration_2_to_3.html#force-override-a-pipeline-method>`__ for more details. ''' if self.sanity_patterns is None: raise SanityError('sanity_patterns not set') with os_ext.change_dir(self._stagedir): success = sn.evaluate(self.sanity_patterns) if not success: raise SanityError()
Example 4
Source File: costar_block_stacking_split_dataset.py From costar_plan with Apache License 2.0 | 6 votes |
def split_sanity_check(train_set, val_set, test_set, len_filenames): # Sanity check for i in val_set: if i in train_set: raise RuntimeError("split_sanity_check: test attempt in train set! %s" % i) for i in test_set: if i in train_set: raise RuntimeError("split_sanity_check: test attempt in train set! %s" % i) for i in test_set: if i in val_set: raise RuntimeError("split_sanity_check: test attempt in val set! %s" % i) if (len(train_set) + len(val_set) + len(test_set)) != len_filenames: print("ERROR! lenth of train, val and test = %d, %d, %d" % (len(train_set), len(val_set), len(test_set))) print("Length of all files: %d" % len_filenames) raise RuntimeError("split_sanity_check: Numbers do not add up!!!") print("Sanity check passed.")
Example 5
Source File: processor.py From indra with BSD 2-Clause "Simplified" License | 6 votes |
def check_statement_sanity(stmt): """Return True if the statement passes some sanity checks.""" # Skip Statement if all agents are None if not any(stmt.agent_list()): raise NoAgents # Skip RegulateActivity if object is None if isinstance(stmt, RegulateActivity): if stmt.obj is None: raise MissingObj if stmt.subj is None: raise MissingSubj if isinstance(stmt, Modification): if stmt.sub is None: raise MissingObj # Skip Complexes with less than 2 members if isinstance(stmt, Complex): if len(stmt.members) < 2: raise UnaryComplex return True
Example 6
Source File: AreaBuilderBase.py From Pirates-Online-Rewritten with BSD 3-Clause "New" or "Revised" License | 6 votes |
def checkSanityOnType(self, objData): objectType = objData['Type'] if objectType != 'Building Exterior': return objectType return objectType file = None try: file = objData['File'] bTrueBuilding = file != '' except: return objectType if not bTrueBuilding: return 'PropBuildingExterior' else: return objectType return
Example 7
Source File: vm_description.py From cot with MIT License | 6 votes |
def check_sanity_of_disk_device(self, disk, file_obj, disk_item, ctrl_item): """Check if the given disk is linked properly to the other objects. Args: disk (object): Disk object to validate file_obj (object): File object which this disk should be linked to (optional) disk_item (object): Disk device object which should link to this disk (optional) ctrl_item (object): Controller device object which should link to the :attr:`disk_item` Raises: ValueMismatchError: if the given items are not linked properly. """ raise NotImplementedError( "check_sanity_of_disk_device not implemented")
Example 8
Source File: monacotests.py From monaco with MIT License | 6 votes |
def check_cluster_sanity(testlogger, r): ''' Check that each cluster has only 1 master ''' result = True m = schema.Monaco() m.refresh(r) for app_id in m.app_ids: cluster = r.hgetall(schema.APP_CLUSTER_TMPL % app_id) master = [k for k,v in cluster.iteritems() if v == 'master'] if len(master) != 1: testlogger.error('App %s has %s masters!' % (app_id, len(master))) result = False invalid = [k for k,v in cluster.iteritems() if not v in ['master', 'slave', 'slave-write']] if len(invalid) > 0: testlogger.error('App %s has an invalid cluster specification: %s', app_id, cluster) result = False return result
Example 9
Source File: config.py From twtxt with MIT License | 6 votes |
def check_config_sanity(self): """Checks if the given values in the config file are sane.""" is_sane = True # This extracts some properties which cannot be checked like "nick", # but it is definitely better than writing the property names as a # string literal. properties = [property_name for property_name, obj in self.__class__.__dict__.items() if isinstance(obj, property)] for property_name in properties: try: getattr(self, property_name) except ValueError as e: click.echo("✗ Config error on {0} - {1}".format(property_name, e)) is_sane = False return is_sane
Example 10
Source File: ds1302.py From SunFounder_SensorKit_for_RPi2 with GNU General Public License v2.0 | 5 votes |
def check_sanity(self): "check sanity of a clock. returns True if clock is sane and False otherwise" dt = self.get_datetime() if dt.year == 2000 or dt.month == 0 or dt.day == 0: return False if dt.second == 80: return False return True
Example 11
Source File: process.py From mpi_learn with GNU General Public License v3.0 | 5 votes |
def check_sanity(self): """Throws an exception if any model attribute has not been set yet.""" for par in ['model', #'weights_shapes', 'weights','update']: if not hasattr(self, par) or getattr(self, par) is None: raise Error("%s not found! Process %s does not seem to be set up correctly." % (par,self.ranks))
Example 12
Source File: 2009isbi.py From 2018DSB with MIT License | 5 votes |
def check_sanity(mask, boundary, folder, fl): _, rest = cv2.connectedComponents(((boundary>0)&(mask==0)).astype('uint8')) vals, counts = np.unique(rest[rest>0], return_counts=True) vals = vals[counts>4] counts = counts[counts>4] if len(vals): plt.imsave(os.path.join('/home/work/dsb/ext/2009isbi/unclosed_boundary', '{}_{}'.format(folder, fl)), (rest>0).astype('uint8')*80) return mask
Example 13
Source File: auxfun_multianimal.py From DeepLabCut with GNU Lesser General Public License v3.0 | 5 votes |
def check_inferencecfg_sanity(cfg, inferencecfg): template = form_default_inferencecfg(cfg) missing = [key for key in template if key not in inferencecfg] if missing: raise KeyError(f'Keys {", ".join(missing)} are missing in the inferencecfg.')
Example 14
Source File: inst2vec_preprocess.py From ncc with BSD 3-Clause "New" or "Revised" License | 5 votes |
def check_sanity(D, G): """ Check construction of dual-XFG :param D: dual XFG :param G: base graph """ isolated_nodes = [n for n in D.nodes() if D.degree(n) == 0] if len(isolated_nodes) is not 0: print("WARNING! Isolated nodes found in D-graph") for n in isolated_nodes: D.remove_node(n) assert "Isolated nodes found in D-graph" if len(list(D.nodes)) != 0: if not nx.is_connected(D): print("WARNING! D-graph is disconnected") assert "D-graph is disconnected" if D.number_of_nodes() != G.number_of_edges(): print("WARNING! The number of nodes in the D-graph (" + str(D.number_of_nodes()) \ + ") does not match the vnumber of edges in the G-graph (" + str( G.number_of_edges()) + ")") assert "Mismatch" ######################################################################################################################## # Main function(s) for XFG-construction ########################################################################################################################
Example 15
Source File: multi_gpu.py From reframe with BSD 3-Clause "New" or "Revised" License | 5 votes |
def do_sanity_check(self): failures = [] devices_found = set(sn.extractall( r'^\s*([^,]*),\s*Detected devices: %s' % self.num_gpus_per_node, self.stdout, 1 )) sn.evaluate(sn.assert_eq( self.job.num_tasks, len(devices_found), msg='requested {0} node(s), got {1} (nodelist: %s)' % ','.join(sorted(devices_found)))) good_nodes = set(sn.extractall( r'^\s*([^,]*),\s*NID\s*=\s*\S+\s+Result = PASS', self.stdout, 1 )) sn.evaluate(sn.assert_eq( devices_found, good_nodes, msg='check failed on the following node(s): %s' % ','.join(sorted(devices_found - good_nodes))) ) # Sanity is fine, fill in the perf. patterns based on the exact node id for nodename in devices_found: for xfer_kind in ('h2d', 'd2h', 'd2d'): for devno in range(self.num_gpus_per_node): perfvar = '%s_gpu_%s_%s_bw' % (nodename, devno, xfer_kind) perfvar = 'bw_%s_%s_gpu_%s' % (xfer_kind, nodename, devno) self.perf_patterns[perfvar] = sn.extractsingle( self._xfer_pattern(xfer_kind, devno, nodename), self.stdout, 1, float, 0 ) partname = self.current_partition.fullname refkey = '%s:%s' % (partname, perfvar) bwkey = '%s:%s' % (partname, xfer_kind) with contextlib.suppress(KeyError): self.reference[refkey] = self.__bwref[bwkey] return True
Example 16
Source File: Trainer.py From truecase with Apache License 2.0 | 5 votes |
def check_sentence_sanity(self, sentence): """ Checks the sanity of the sentence. If the sentence is for example all uppercase, it is rejected """ case_dist = nltk.FreqDist() for token in sentence: case_dist[self.get_casing(token)] += 1 if case_dist.most_common(1)[0][0] != "allLower": return False return True
Example 17
Source File: IceIterative2.py From cDNA_Cupcake with BSD 3-Clause Clear License | 5 votes |
def check_cluster_sanity(self, check_dir_lambda=(lambda x: False)): """Check cluster sanity.""" _membership = {} try: for cid, members in self.uc.items(): assert len(members) > 0 for x in members: assert x not in _membership _membership[x] = cid if (cid not in self.refs or len(self.refs[cid]) == 0): print("ref for {0} does not exist!".format(cid)) elif check_dir_lambda(cid): # or random.random() <= .01: self.add_log("Randomly checking {cid}".format(cid=cid)) seqids = set(line.strip()[1:].split()[0] for line in os.popen("grep \">\" " + self.clusterInFa(cid))) assert seqids == set(members) assert op.exists(self.refs[cid]) for x in self.d: if len(self.d[x]) == 1 and list(self.d[x].values())[0] == 0: cid = list(self.d[x].keys())[0] assert len(self.uc[cid]) >= self.rerun_gcon_size except AssertionError: errMsg = "Cluster sanity check failed!" self.add_log(errMsg, level=logging.ERROR) raise ValueError(errMsg) return _membership
Example 18
Source File: hf.py From pyscf with Apache License 2.0 | 5 votes |
def check_sanity(self): mol_hf.SCF.check_sanity(self) self.with_df.check_sanity() if (isinstance(self.exxdiv, str) and self.exxdiv.lower() != 'ewald' and isinstance(self.with_df, df.df.DF)): logger.warn(self, 'exxdiv %s is not supported in DF or MDF', self.exxdiv) return self
Example 19
Source File: causal.py From ravestate with BSD 3-Clause "New" or "Revised" License | 5 votes |
def check_reference_sanity(self) -> bool: """ Make sure, that the refcount-per-act-per-spike-per-resource value sum is equal to the number of spikes from this causal group acquired per activation for each activation in the index. :return: True if the criterion is fulfilled, False otherwise. """ result = True signals_with_cause = set() for act in self._non_detached_activations(): sum_refcount = sum( refc_per_act[act] for resource in act.resources() for refc_per_act in self._ref_index[resource].values() if act in refc_per_act) sum_spikes = sum( len(act.resources()) for signal in act.constraint.signals() if signal.spike and signal.spike.causal_group() == self) if sum_spikes != sum_refcount: logger.error(f"Mutual refcount mismatch: {self} -> {sum_refcount} : {sum_spikes} <- {act}") result = False for sig in act.possible_signals(): signals_with_cause.add(sig) if sig in self._uncaused_spikes: causes = sum_spikes / len(act.resources()) if self._uncaused_spikes[sig][act] != causes: logger.error(f"Signal cause mismatch for {sig} by {act}: is {self._uncaused_spikes[sig][act]}, " f"should be {causes}") result = False for signal in set(self._uncaused_spikes.keys())-signals_with_cause: logger.error(f"Signal cause mismatch for {signal}: is {self._uncaused_spikes[signal]}, " f"should be ZERO") result = False return result
Example 20
Source File: rotate.py From pytomo3d with GNU Lesser General Public License v3.0 | 5 votes |
def check_horizontal_inventory_sanity(tr1, tr2, inventory): """ Check two horizontal components and see if their dip is 0 and azimuth is orthogonal to each other. :param tr1: :param tr2: :param inventory: :return: """ if tr1.id[:-1] != tr2.id[:-1]: raise ValueError("Two horizontal ids should share the same network," "station, location and channel[0:2]: %s, %s" % (tr1.id, tr2.id)) if tr1.stats.channel[-1] == "Z" or tr2.stats.channel[-1] == "Z": raise ValueError("Functions should check two horizontal component:" "%s, %s" % (tr1.id, tr2.id)) dip1, azi1 = extract_channel_orientation(tr1, inventory) dip2, azi2 = extract_channel_orientation(tr2, inventory) if dip1 is None or azi1 is None or dip2 is None or azi2 is None: return False # check dip if not np.isclose(dip1, 0.0) or not np.isclose(dip2, 0.0): return False # check azimuth if not check_orthogonality(azi1, azi2): return False return True
Example 21
Source File: store.py From landscape-client with GNU General Public License v2.0 | 5 votes |
def check_sanity(self, cursor): """Check database integrity. @raise: L{InvalidHashIdDb} if the filenme passed to the constructor is not a SQLite database or does not have a table called "hash" with a compatible schema. """ try: cursor.execute("SELECT id FROM hash WHERE hash=?", ("",)) except sqlite3.DatabaseError: raise InvalidHashIdDb(self._filename)
Example 22
Source File: kitti_dataset.py From image-segmentation with MIT License | 5 votes |
def check_sanity(self): for i in tqdm(self.image_ids): assert self.image_files[i][:-4] == self.label_files[i][:-4],\ 'image - label filename mismatch: {} - {}'.format(self.image_files[i], self.label_files[i]) img = load_image_rgb(os.path.join(self.image_dir, self.image_files[i])) msk = load_image_rgb(os.path.join(self.label_dir, self.label_files[i])) assert img.shape == msk.shape,\ 'img.shape: {}, msk.shape: {}'.format(img.shape, msk.shape)
Example 23
Source File: stats_datastruct.py From douglas-quaid with GNU General Public License v3.0 | 5 votes |
def check_sanity(self): try: if not (self.P == self.FN + self.TP): raise Exception("Positives != False negative + true positive") if not (self.N == self.FN + self.TP + self.FP): raise Exception("Negatives != False negative + true positive + False positive") if not (self.N <= self.TN): raise Exception("Negatives !<= True negatives") if not (self.P >= self.TP): raise Exception("Positives !>= True positives") return True except Exception as e: print(e) return False # Operator overwrite # TODO : Review ">" operator
Example 24
Source File: TrainFunctions.py From truecaser with Apache License 2.0 | 5 votes |
def checkSentenceSanity(sentence): """ Checks the sanity of the sentence. If the sentence is for example all uppercase, it is recjected""" caseDist = nltk.FreqDist() for token in sentence: caseDist[getCasing(token)] += 1 if caseDist.most_common(1)[0][0] != 'allLower': return False return True
Example 25
Source File: monacotests.py From monaco with MIT License | 5 votes |
def check_job_queue_sanity(testlogger, r, limit=5): ''' Ensure that there are less than limit jobs pending in queue ''' return r.llen(schema.MONACO_JOB_QUEUE) <= limit
Example 26
Source File: glyphObjects.py From Robofont-scripts with MIT License | 5 votes |
def checkSanity(self): self.updateIndices() points = self.points closed = self.isClosed if len(points) > 0: # check closed contour starts with a OnCurve point if closed: if points[0].segmentType is None: points.insert(0, points.pop()) if points[-1].segmentType is None: points[0].segmentType = 'curve' if not closed: points[0].segmentType = 'move' for i, point in enumerate(points): previousPoint = points[(i-1)%len(points)] nextPoint = points[(i+1)%len(points)] # segmentType legality if i == 0: if (not closed and (point.segmentType == 'curve')) or \ (closed and (point.segmentType == 'curve') and (self.getLast().segmentType is not None)): point.segmentType = 'line' if i > 0: if point.segmentType in ['curve', 'move'] and previousPoint.segmentType is not None: point.segmentType = 'line' elif point.segmentType in ['line','move'] and previousPoint.segmentType is None: point.segmentType = 'curve' elif point.segmentType is None and previousPoint.segmentType is not None and nextPoint.segmentType is not None: point.segmentType = 'line' self.points = points self.updateIndices()
Example 27
Source File: domain.py From rasa_core with Apache License 2.0 | 4 votes |
def check_domain_sanity(domain): """Make sure the domain is properly configured. Checks the settings and checks if there are duplicate actions, intents, slots and entities.""" def get_duplicates(my_items): """Returns a list of duplicate items in my_items.""" return [item for item, count in collections.Counter(my_items).items() if count > 1] def check_mappings(intent_properties): """Check whether intent-action mappings use proper action names.""" incorrect = list() for intent, properties in intent_properties.items(): if 'triggers' in properties: if properties.get('triggers') not in domain.action_names: incorrect.append((intent, properties['triggers'])) return incorrect def get_exception_message( duplicates: Optional[List[Tuple[List[Text], Text]]] = None, mappings: List[Tuple[Text, Text]] = None): """Return a message given a list of error locations.""" message = "" if duplicates: message += get_duplicate_exception_message(duplicates) if mappings: if message: message += "\n" message += get_mapping_exception_message(mappings) return message def get_mapping_exception_message(mappings: List[Tuple[Text, Text]]): """Return a message given a list of duplicates.""" message = "" for name, action_name in mappings: if message: message += "\n" message += ("Intent '{}' is set to trigger action '{}', which is " "not defined in the domain.".format(name, action_name)) return message def get_duplicate_exception_message( duplicates: List[Tuple[List[Text], Text]] ) -> Text: """Return a message given a list of duplicates.""" message = "" for d, name in duplicates: if d: if message: message += "\n" message += ("Duplicate {0} in domain. " "These {0} occur more than once in " "the domain: {1}".format(name, ", ".join(d))) return message duplicate_actions = get_duplicates(domain.action_names) duplicate_intents = get_duplicates(domain.intents) duplicate_slots = get_duplicates([s.name for s in domain.slots]) duplicate_entities = get_duplicates(domain.entities) incorrect_mappings = check_mappings(domain.intent_properties) if (duplicate_actions or duplicate_intents or duplicate_slots or duplicate_entities or incorrect_mappings): raise InvalidDomain(get_exception_message([ (duplicate_actions, "actions"), (duplicate_intents, "intents"), (duplicate_slots, "slots"), (duplicate_entities, "entities")], incorrect_mappings))
Example 28
Source File: domain.py From rasa_wechat with Apache License 2.0 | 4 votes |
def check_domain_sanity(domain): """Makes sure the domain is properly configured. Checks the settings and checks if there are duplicate actions, intents, slots and entities.""" def get_duplicates(my_items): """Returns a list of duplicate items in my_items.""" return [item for item, count in collections.Counter(my_items).items() if count > 1] def get_exception_message(duplicates): """Returns a message given a list of error locations. Duplicates has the format of (duplicate_actions [List], name [Text]). :param duplicates: :return: """ msg = "" for d, name in duplicates: if d: if msg: msg += "\n" msg += ("Duplicate {0} in domain. " "These {0} occur more than once in " "the domain: {1}".format(name, ", ".join(d))) return msg duplicate_actions = get_duplicates([a for a in domain.actions]) duplicate_intents = get_duplicates([i for i in domain.intents]) duplicate_slots = get_duplicates([s.name for s in domain.slots]) duplicate_entities = get_duplicates([e for e in domain.entities]) if duplicate_actions or \ duplicate_intents or \ duplicate_slots or \ duplicate_entities: raise Exception(get_exception_message([ (duplicate_actions, "actions"), (duplicate_intents, "intents"), (duplicate_slots, "slots"), (duplicate_entities, "entitites")]))