Best Python code snippet using autotest_python
sisxmlparser2_2_py3.py
Source:sisxmlparser2_2_py3.py
...186 def gds_format_integer(self, input_data):187 return '%d' % input_data188 def gds_validate_integer(self, input_data, node):189 return input_data190 def gds_format_float(self, input_data):191 # #362 - Shorten the display for the zeros.192 if input_data == 0.0:193 return '%.1f' % input_data194 return '%.12E' % input_data195 def gds_validate_float(self, input_data, node):196 return input_data197 def gds_format_double(self, input_data):198 # #362 - Shorten the display for the zeros.199 if input_data == 0.0:200 return '%.1f' % input_data201 return '%.12E' % input_data202 def gds_validate_double(self, input_data, node):203 return input_data204 def gds_format_decimal(self, input_data):205 return '%s' % input_data206 def gds_validate_decimal(self, input_data, node):207 return input_data208 def gds_format_boolean(self, input_data):209 return ('%s' % input_data).lower()210 def gds_validate_boolean(self, input_data, node):211 return input_data212 def gds_validate_datetime(self, input_data, node):213 return input_data214 def gds_format_datetime(self, input_data):215 if input_data.microsecond == 0:216 _svalue = '%04d-%02d-%02dT%02d:%02d:%02d' % (217 input_data.year,218 input_data.month,219 input_data.day,220 input_data.hour,221 input_data.minute,222 input_data.second,223 )224 else:225 _svalue = '%04d-%02d-%02dT%02d:%02d:%02d.%s' % (226 input_data.year,227 input_data.month,228 input_data.day,229 input_data.hour,230 input_data.minute,231 input_data.second,232 ('%f' % (float(input_data.microsecond) / 1000000))[2:],233 )234 if input_data.tzinfo is not None:235 tzoff = input_data.tzinfo.utcoffset(input_data)236 if tzoff is not None:237 total_seconds = tzoff.seconds + (86400 * tzoff.days)238 if total_seconds == 0:239 _svalue += 'Z'240 else:241 if total_seconds < 0:242 _svalue += '-'243 total_seconds *= -1244 else:245 _svalue += '+'246 hours = total_seconds // 3600247 minutes = (total_seconds - (hours * 3600)) // 60248 _svalue += '{0:02d}:{1:02d}'.format(hours, minutes)249 else:250 # assume it is in UTC if no timezone info is specified.251 _svalue += 'Z'252 return _svalue253 def gds_parse_datetime(cls, input_data):254 '''Parse an xml date string with timezone information.255 Return a datetime object with time in UTC'''256 tzoff_pattern = re_.compile(r'(\+|-)((0\d|1[0-3]):[0-5]\d|14:00)$')257 tzoff = 0258 if input_data[-1] == 'Z':259 # it is in UTC260 input_data = input_data[:-1]261 else:262 # not in UTC. Get the offset in minutes263 results = tzoff_pattern.search(input_data)264 if results is not None:265 tzoff_parts = results.group(2).split(':')266 tzoff = int(tzoff_parts[0]) * 60 + int(tzoff_parts[1])267 if results.group(1) == '-':268 tzoff *= -1269 input_data = input_data[:-6]270 if len(input_data.split('.')) > 1:271 dt = datetime_.datetime.strptime(272 input_data, '%Y-%m-%dT%H:%M:%S.%f')273 else:274 dt = datetime_.datetime.strptime(275 input_data, '%Y-%m-%dT%H:%M:%S')276 dt = dt - datetime_.timedelta(minutes=tzoff)277 return dt278class SISBase(MyBase):279 '''Base class for the extended FDSN StationXML.'''280 EOL = '\n'281 INDENT = ' '282 ELEMS = () #for each element create a tuple with name, datatype, isrequired, ismultivalue283 ATTRIBS = (('xsi:type', 'text', False, False), )284 NS = '' #Set the XML namespace for each class. Set 'fsx' for types in FDSNStationXML and 'sis' for the types in the SIS extension.285 EXTNS = '' # Set a value only when the extension is in a different namespace from the super class286 EXTTYPE = '' # Set a value only for the sis types that extend from types defined in FDSNStationXML. Use EXTNS:EXTTYPE to set the value for xsi:type287 SUPERCLASS = '' #Set a value only when the extension is in a different namespace from the super class288 def __init__(self, **kw):289 self.elemdict = dict([(e[0], e[1:]) for e in self.ELEMS])290 self.attribdict = dict([(e[0], e[1:]) for e in self.ATTRIBS])291 for e in list(self.elemdict.keys()) + list(self.attribdict.keys()):292 if e in kw:293 setattr(self, e, kw.pop(e))294 if kw:295 raise SISError('Unexpected keys %s' % kw)296 def settype(self, type):297 setattr(self, 'xsi:type', type)298 def build(self, node):299 '''Read and set the attributes for this node and call function to read child nodes '''300 self.ns, self.nodename = get_ns_nodename(node)301 for k, v in list(node.attrib.items()):302 #remove the namespaceuris and replace with the namespaceprefix303 for uri,prefix in list(insd.items()):304 k = k.replace('{'+uri+'}', prefix + ':')305 if k in self.attribdict:306 if k == 'xsi:type':307 #store the remapped prefix:type308 val = get_remapped_type(v)309 else:310 datatype, isreqd, ismulti = self.attribdict[k]311 if datatype == 'text':312 val = v313 elif datatype == 'float' or datatype == 'decimal':314 val = cast_to_float(v, None)315 elif datatype == 'integer':316 val = cast_to_integer(v, None)317 elif datatype == 'boolean':318 val = cast_to_bool(v, None)319 elif datatype == 'date':320 val = self.gds_parse_datetime(v)321 else:322 raise SISError ('Unknown datatype %s for attribute %s' %(datatype, k))323 self.__dict__[k] = val324 for child in node:325 self.buildchildren(child, node)326 def buildchildren(self, child, node):327 '''Parse the child node and save all elements to the instance of this class and call function to read its child nodes'''328 cns, cname, ctype = get_ns_name_type(child)329 # If unknown namespace ignore the element/node330 if cns is None:331 return332 if cname in self.elemdict:333 datatype, isreqd, ismulti = self.elemdict[cname]334 if datatype == 'text':335 val = get_text(child)336 elif datatype == 'float' or datatype == 'decimal':337 val = cast_to_float(get_text(child), child)338 elif datatype == 'integer':339 val = cast_to_integer(get_text(child), child)340 elif datatype == 'boolean':341 val = cast_to_bool(get_text(child), child)342 elif datatype == 'date':343 val = self.gds_parse_datetime(get_text(child))344 #handle the objects345 else:346 val = datatype()347 #Get the type defined in xml in the attribute xsi:type. Note this type value has been remapped.348 nstype = None349 if val.EXTNS and val.EXTTYPE:350 nstype = '%s:%s' % (val.EXTNS, val.EXTTYPE)351 #Verify that the type defined in xml uses the correponding class in python352 if ctype and ctype != nstype:353 print(('Type defined in xml %s, using class %s' % (ctype, datatype)))354 val.build(child)355 # Note that val might contain a simple value or an object. If this element can have multiple values make a list.356 if ismulti:357 if not hasattr(self, cname):358 self.__dict__[cname] = []359 self.__dict__[cname].append(val)360 else:361 self.__dict__[cname] = val362 else:363 #unknown or unexpected element. raise error.364 raise SISError ('Unknown element %s:%s under node %s'% (cns, cname, self.nodename))365 def validate(self):366 # this function is to be extended in the classes where applicable.367 pass368 def exportdict(self):369 '''Return a python dictionary of this object's elements '''370 exp ={}371 #validate the content of this object372 self.validate()373 all = dict(list(self.elemdict.items()) + list(self.attribdict.items()))374 for k, v in list(all.items()):375 datatype, isreqd, ismulti = v376 if hasattr(self, k):377 if getattr(self, k) is None and isreqd:378 raise SISError('Expected non-null value for required element or attribute %s'%k)379 if isinstance(datatype, str):380 # The builtin datatypes of str/float/integer/date are listed as string literals. Single or multivalues both are handled simply.381 exp[k] = getattr(self, k)382 else:383 # Datatype is a type matching the xml complex type.384 # Export the contents as a dictionary385 if ismulti:386 # Multivalue possible, stored as a list. Export a list of dictionaries387 exp[k] = []388 objs = getattr(self, k)389 for o in objs:390 exp[k].append(o.exportdict())391 else:392 obj = getattr(self, k)393 exp[k] = obj.exportdict()394 else:395 if isreqd:396 raise SISError('Missing required element or attribute %s'% (k))397 return exp398 def getattrxml (self):399 '''400 Return a string containing all the attribute key value pairs with a leading space401 or an empty string if there are no attributes.402 '''403 alist = []404 for k, datatype, isreqd, ismulti in self.ATTRIBS:405 if hasattr(self, k):406 v = getattr(self, k)407 if datatype == 'text':408 val = self.gds_format_string(quote_attrib(v))409 elif datatype == 'float':410 val = self.gds_format_float(v)411 elif datatype == 'decimal':412 val = self.gds_format_decimal(v)413 elif datatype == 'integer':414 val = self.gds_format_integer(v)415 elif datatype == 'date':416 val = self.gds_format_datetime(v)417 elif datatype == 'boolean':418 val = self.gds_format_boolean(v)419 alist.append('%s="%s"' % (k,val))420 axml = ''421 if alist:422 axml = ' ' + ' '.join(alist)423 return axml424 def exportxml(self, outfile, tag, tagns, level):425 '''Write the xml for this object and its subelements. '''426 # Get an xml string with attributes formatted as key='val'427 axml = self.getattrxml()428 if level == 0:429 #write the xxml doctype430 outfile.write('<?xml version="1.0" ?>\n')431 #write out the namespaces and prefixes in the attribute list432 for prefix, uri in list(nsd.items()):433 axml = axml + ' xmlns:%s="%s"' % (prefix, uri)434 #validate the content of this object435 self.validate()436 outfile.write('%s<%s:%s%s>%s' % (self.INDENT*level, tagns, tag, axml, self.EOL))437 sublevel = level + 1438 #use the tuple self.ELEMS because the order is important439 for k, datatype, isreqd, ismulti in self.ELEMS:440 # in case the extended type is in a different namespace then self.EXTNS has been set441 ns = self.NS442 if self.EXTNS:443 sup = self.SUPERCLASS444 #if element is not in the superclass then use self.EXTNS as the namespace prefix445 if k not in [e[0] for e in sup.ELEMS]:446 ns = self.EXTNS447 if hasattr(self, k):448 if getattr(self,k) is None:449 if isreqd:450 raise SISError('Expected non-null value for required element or attribute %s in %s'% (k, tag))451 else:452 #TODO check encoding and formatting. Does double and float need to be handled differently?453 if not ismulti:454 v = getattr(self, k)455 if isinstance(datatype, str):456 if datatype == 'text':457 #TODO check encoding for string458 val = self.gds_format_string(quote_xml(v))459 elif datatype == 'float':460 val = self.gds_format_float(v)461 elif datatype == 'decimal':462 val = self.gds_format_decimal(v)463 elif datatype == 'integer':464 val = self.gds_format_integer(v)465 elif datatype == 'date':466 val = self.gds_format_datetime(v)467 elif datatype == 'boolean':468 val = self.gds_format_boolean(v)469 outfile.write('%s<%s:%s>%s</%s:%s>%s' % (self.INDENT*sublevel, ns, k, val, ns, k, self.EOL))470 else:471 v.exportxml(outfile, k, ns, level+1)472 else:473 vlist = getattr(self, k)474 for v in vlist:475 if isinstance(datatype, str):476 if datatype == 'text':477 #TODO check encoding for string478 val = self.gds_format_string(quote_xml(v))479 elif datatype == 'float':480 val = self.gds_format_float(v)481 elif datatype == 'decimal':482 val = self.gds_format_decimal(v)483 elif datatype == 'integer':484 val = self.gds_format_integer(v)485 elif datatype == 'date':486 val = self.gds_format_datetime(v)487 elif datatype == 'boolean':488 val = self.gds_format_boolean(v)489 outfile.write('%s<%s:%s>%s</%s:%s>%s' % (self.INDENT*sublevel, ns, k, val, ns, k, self.EOL))490 else:491 v.exportxml(outfile, k, ns, sublevel)492 else:493 if isreqd:494 raise SISError('Missing required element or attribute %s in %s'% (k, tag))495 outfile.write('%s</%s:%s>%s' % (self.INDENT*level, tagns, tag, self.EOL))496 def exportobj(self, outfile, level):497 '''Write out a python object representation. '''498 self.validate()499 if level == 0:500 #For the outer most class add its name501 outfile.write('%s=%s(%s' % ('rootobj', self.__class__.__name__, self.EOL))502 level = level +1503 for (k, datatype, isreqd, ismulti) in self.ATTRIBS + self.ELEMS:504 if k in self.__dict__:505 v = getattr(self, k)506 if isinstance(datatype, str):507 if datatype == 'text' and not ismulti:508 outfile.write("%s%s='%s',%s" % (self.INDENT*level, k, v, self.EOL))509 else:510 outfile.write('%s%s=%s,%s' % (self.INDENT*level, k, v, self.EOL))511 else:512 if ismulti:513 outfile.write('%s%s=[%s' % (self.INDENT*level, k, self.EOL))514 level = level+1515 for elem in v:516 outfile.write('%s%s(%s' %(self.INDENT*level, elem.__class__.__name__, self.EOL))517 elem.exportobj(outfile, level+1)518 outfile.write ('%s),%s' %(self.INDENT*level, self.EOL))519 outfile.write('%s],%s' %(self.INDENT*level, self.EOL))520 level = level - 1521 else:522 outfile.write('%s%s=%s(%s' %(self.INDENT*level, k, v.__class__.__name__, self.EOL))523 v.exportobj(outfile, level+1)524 outfile.write ('%s),%s' %(self.INDENT*level, self.EOL))525 if level == 1:526 #close the outer most class527 outfile.write(')%s'%(self.EOL,))528class SISSimpleType(SISBase):529 '''530 Use this class for simple types that have no sub-elements, but have attributes.531 Redefine ElEMS if not of type text. Should be a tuple containing info for only532 one element named ValueOf.533 '''534 ELEMS = (('ValueOf', 'text', True, False),)535 NS = 'fsx'536 def build(self, node):537 self.ns, self.nodename = get_ns_nodename(node)538 ndatatype = self.ELEMS[0][1]539 v = node.text.strip()540 if ndatatype == 'text':541 val = v542 elif ndatatype == 'float' or ndatatype == 'decimal':543 val = cast_to_float(v, None)544 elif ndatatype == 'integer':545 val = cast_to_integer(v, None)546 elif ndatatype == 'boolean':547 val = cast_to_bool(v, None)548 elif ndatatype == 'date':549 val = self.gds_parse_datetime(v)550 else:551 raise SISError ('Unknown datatype %s' %datatype)552 self.ValueOf = val553 for k, v in list(node.attrib.items()):554 if k in self.attribdict:555 datatype, isreqd, ismulti = self.attribdict[k]556 if datatype == 'text':557 val = v558 elif datatype == 'float' or datatype =='decimal':559 val = cast_to_float(v, None)560 elif datatype == 'integer':561 val = cast_to_integer(v, None)562 elif datatype == 'boolean':563 val = cast_to_bool(v, None)564 elif datatype == 'date':565 val = self.gds_parse_datetime(v)566 else:567 raise SISError ('Unknown datatype %s' %datatype)568 self.__dict__[k] = val569 else:570 raise SISError ('Unexpected attribute %s=%s in node %s in class%s' %(k, v, self.nodename, self.__class__.__name__))571 def buildchildren(self, child, node):572 pass573 def exportxml(self, outfile, tag, tagns, level):574 '''Export the value in ValueOf as the content of the passed in tag. '''575 axml = self.getattrxml()576 #validate the content of this object577 self.validate()578 (ndatatype, isreqd) = self.ELEMS[0][1:3]579 if isreqd and self.ValueOf is None:580 raise SISError('Expected non-null value for required element %s'% (tag))581 if ndatatype == 'text':582 val = self.gds_format_string(quote_xml(self.ValueOf))583 elif ndatatype == 'float':584 val = self.gds_format_float(self.ValueOf)585 elif ndatatype == 'decimal':586 val = self.gds_format_decimal(self.ValueOf)587 elif ndatatype == 'integer':588 val = self.gds_format_integer(self.ValueOf)589 elif ndatatype == 'date':590 val = self.gds_format_datetime(self.ValueOf)591 elif ndatatype == 'boolean':592 val = self.gds_format_boolean(self.ValueOf)593 outfile.write('%s<%s:%s%s>%s</%s:%s>%s' % (self.INDENT*level, tagns, tag, axml, val, tagns, tag, self.EOL))594class UnitsType(SISBase):595 ELEMS = (('Name', 'text', True, False),596 ('Description', 'text', False, False),597 )598 NS = 'fsx'599class FloatNoUnitType(SISSimpleType):600 '''601 This is a SimpleType node602 '''603 ELEMS = (('ValueOf', 'float', True, False),)604 ATTRIBS = SISSimpleType.ATTRIBS + (('plusError', 'float', False , False),605 ('minusError', 'float', False , False),606 ('number', 'integer', False , False),607 )608 NS = 'fsx'609 def validate(self):610 plus = getattr(self, 'plusError', None)611 minus = getattr(self, 'minusError', None)612 if plus != minus:613 raise SISError ('The plus error and minus error are different. The loader requires them to be the same. Class %s, plus error %s, minus error %s'%(self.__class__.__name__, plus, minus))614 super(FloatNoUnitType, self).validate()615class FloatType(FloatNoUnitType):616 ATTRIBS = FloatNoUnitType.ATTRIBS + (('unit', 'text', False, False),617 ('i', 'integer', False, False),)618 NS = 'fsx'619class FrequencyType(FloatType):620 def validate(self):621 if hasattr(self, 'unit') and self.unit != 'HERTZ':622 raise SISError ('Frequency unit should be HERTZ. It is specified as %s' % self.unit)623 super(FrequencyType, self).validate()624class DecimationType(SISBase):625 ELEMS = (('InputSampleRate', FrequencyType, True, False),626 ('Factor', 'integer', True, False),627 ('Offset', 'integer', True, False),628 ('Delay', 'float', True, False),629 ('Correction', 'float', True, False),630 )631 NS = 'fsx'632class GainType(SISBase):633 ELEMS = (('Value', 'float', True, False),634 ('Frequency', 'float', True, False),635 )636 NS = 'fsx'637class SensitivityType(GainType):638 ELEMS = GainType.ELEMS + (('InputUnits', UnitsType, True, False),639 ('OutputUnits', UnitsType, True, False),640 ('FrequencyStart', 'float', False, False),641 ('FrequencyEnd', 'float', False, False),642 ('FrequencyDBVariation', 'float', False, False),643 )644 NS = 'fsx'645class SISGainType (GainType):646 ELEMS = GainType.ELEMS + (('InputUnits', UnitsType, False, False),647 ('OutputUnits', UnitsType, False, False),648 )649 EXTNS = 'sis'650 EXTTYPE = 'GainType' # Use EXTNS:EXTTYPE to set the value for xsi:type651 SUPERCLASS = GainType652class PoleZeroType(SISBase):653 ELEMS = (('Real', FloatNoUnitType, True, False),654 ('Imaginary', FloatNoUnitType, True, False),655 )656 ATTRIBS = SISBase.ATTRIBS + (('number', 'integer', False, False),)657 NS = 'fsx'658class BaseFilterType(SISBase):659 #Units are required in XSD, but not required for the loader.660 ELEMS = (('Description', 'text', False, False),661 ('InputUnits', UnitsType, False, False),662 ('OutputUnits', UnitsType, False, False),663 )664 ATTRIBS = SISBase.ATTRIBS + (('resourceid', 'text', False, False),665 ('name', 'text', False, False),666 )667 NS = 'fsx'668class PolesZerosType(BaseFilterType):669 ELEMS = BaseFilterType.ELEMS + (('PzTransferFunctionType', 'text', True, False),670 ('NormalizationFactor', 'float', True, False),671 ('NormalizationFrequency', 'float', True, False),672 ('Zero', PoleZeroType, False, True),673 ('Pole', PoleZeroType, False, True),674 )675 NS = 'fsx'676class SISPolesZerosType(PolesZerosType):677 ATTRIBS = PolesZerosType.ATTRIBS + (('SISNamespace', 'text', True, False),)678 EXTNS = 'sis'679 EXTTYPE = 'PolesZerosType' # Use EXTNS:EXTTYPE to set the value for xsi:type680 SUPERCLASS = PolesZerosType681class CoefficientsType (BaseFilterType):682 ELEMS = BaseFilterType.ELEMS + (('CfTransferFunctionType', 'text', True, False),683 ('Numerator', FloatType, False, True),684 ('Denominator', FloatType, False, True),685 )686 NS = 'fsx'687class SISCoefficientsType(CoefficientsType):688 ATTRIBS = CoefficientsType.ATTRIBS + (('SISNamespace', 'text', True, False),)689 EXTNS = 'sis'690 EXTTYPE = 'CoefficientsType' # Use EXTNS:EXTTYPE to set the value for xsi:type691 SUPERCLASS = CoefficientsType692class FIRType(BaseFilterType):693 ELEMS = BaseFilterType.ELEMS + (('Symmetry', 'text', True, False),694 ('NumeratorCoefficient', FloatType, False, True),695 )696 NS = 'fsx'697class SISFIRType(FIRType):698 ATTRIBS = FIRType.ATTRIBS + (('SISNamespace', 'text', True, False),)699 EXTNS = 'sis'700 EXTTYPE = 'FIRType' # Use EXTNS:EXTTYPE to set the value for xsi:type701 SUPERCLASS = FIRType702class PolynomialType(BaseFilterType):703 ELEMS = BaseFilterType.ELEMS + (('ApproximationType', 'text', True, False),704 ('FrequencyLowerBound', FrequencyType, True, False),705 ('FrequencyUpperBound', FrequencyType, True, False),706 ('ApproximationLowerBound', 'decimal', True, False),707 ('ApproximationUpperBound', 'decimal', True, False),708 ('MaximumError', 'decimal', True, False),709 ('Coefficient', FloatNoUnitType, True, True),710 )711 NS = 'fsx'712class SISPolynomialType(PolynomialType):713 ATTRIBS = PolynomialType.ATTRIBS + (('SISNamespace', 'text', True, False),)714 EXTNS = 'sis'715 EXTTYPE = 'PolynomialType' # Use EXTNS:EXTTYPE to set the value for xsi:type716 SUPERCLASS = PolynomialType717class PersonType(SISBase):718 ELEMS = (('Name', 'text', False, True),719 ('Agency', 'text', False, True),720 ('Email', 'text', False, True),721 ('Phone', 'text', False, True),722 )723 NS = 'fsx'724class CommentType(SISBase):725 ELEMS = (('Value', 'text', True, False),726 ('BeginEffectiveTime', 'date', False, False),727 ('EndEffectiveTime', 'date', False, False),728 ('Author', PersonType, False, True),729 )730 NS = 'fsx'731class BaseNodeType (SISBase):732 ELEMS = (('Description', 'text', False, False),733 ('Comment', CommentType, False, True),734 )735 ATTRIBS = SISBase.ATTRIBS + (('code', 'text', True, False),736 ('startDate', 'date', False, False),737 ('endDate', 'date', False, False),738 ('restrictedStatus', 'text', False, False),739 ('alternateCode', 'text', False, False),740 ('historicalCode', 'text', False, False),)741 NS = 'fsx'742class LatitudeType(FloatType):743 ATTRIBS = FloatType.ATTRIBS + (('datum', 'text', False, False),)744 NS = 'fsx'745 def validate(self):746 if hasattr(self, 'unit') and self.unit != 'DEGREES':747 raise SISError ('Latitude should be in DEGREES. It is specified as %s'% self.unit)748 if self.ValueOf <-90 or self.ValueOf > 90:749 raise SISError('Invalid Latitude %s'% self.ValueOf)750 super(LatitudeType, self).validate()751 #Override default exponential out format and precision defined for FloatType752 def gds_format_float(self, input_data):753 return '%.6f' % input_data754class LongitudeType(FloatType):755 ATTRIBS = FloatType.ATTRIBS + (('datum', 'text', False, False),)756 NS = 'fsx'757 def validate(self):758 if hasattr(self, 'unit') and self.unit != 'DEGREES':759 raise SISError ('Longitude should be in DEGREES. It is specified as %s'% self.unit)760 if self.ValueOf <-180 or self.ValueOf > 180:761 raise SISError('Invalid Longitude %s'% self.ValueOf)762 super(LongitudeType, self).validate()763 #Override default exponential out format and precision defined for FloatType764 def gds_format_float(self, input_data):765 return '%.6f' % input_data766class AzimuthType(FloatType):767 NS = 'fsx'768 def validate(self):769 if hasattr(self, 'unit') and self.unit != 'DEGREES':770 raise SISError ('Azimuth should be in DEGREES. It is specified as %s'% self.unit)771 if self.ValueOf <0 or self.ValueOf > 360:772 raise SISError('Invalid Azimuth %s'% self.ValueOf)773 super(AzimuthType, self).validate()774 #Override default exponential out format and precision defined for FloatType775 def gds_format_float(self, input_data):776 return '%.1f' % input_data777class DipType(FloatType):778 NS = 'fsx'779 def validate(self):780 if hasattr(self, 'unit') and self.unit != 'DEGREES':781 raise SISError ('Dip should be in DEGREES. It is specified as %s'% self.unit)782 if self.ValueOf < -90 or self.ValueOf > 90:783 raise SISError('Invalid Dip %s'% self.ValueOf)784 super(DipType, self).validate()785 #Override default exponential out format and precision defined for FloatType786 def gds_format_float(self, input_data):787 return '%.1f' % input_data788class DistanceType(FloatType):789 NS = 'fsx'790 def validate(self):791 if hasattr(self, 'unit') and self.unit != 'METERS':792 raise SISError ('Distance should be in METERS. It is specified as %s'% self.unit)793 super(DistanceType, self).validate()794 #Override default exponential out format and precision defined for FloatType795 def gds_format_float(self, input_data):796 return '%.1f' % input_data797class ExternalReferenceType(SISBase):798 ELEMS = (('URI', 'text', True, False),799 ('Description', 'text', True, False),800 )801 NS = 'fsx'802class SampleRateRatioType(SISBase):803 ELEMS = (('NumberSamples', 'integer', True, False),804 ('NumberSeconds', 'integer', True, False),805 )806 NS = 'fsx'807class EquipmentType(SISBase):808 ELEMS = (('Type', 'text', False, False),809 ('Description', 'text', False, False),...
emdb_user_methods.py
Source:emdb_user_methods.py
...125# Replace the following method specifications with your own.126#127# Sample method specification #1128#129method1 = MethodSpec(name='gds_format_float', source='''def gds_format_float(self,input_data, input_name="" ): return ("%%g" %% input_data)''',130 class_names=r'^resolutionType$|^contourType$|^contourLevelType$|^chamber_humidityType$|^eWindowType$|^vitrifType$|^imgType$|^originType$|^limitType$',131 )132#133# Provide a list of your method specifications.134# This list of specifications must be named METHOD_SPECS.135#136METHOD_SPECS = (method1,)137def test():138 """139 TO DO:140 """141 for spec in METHOD_SPECS:142 spec.show()143def main():...
Coordinates.py
Source:Coordinates.py
...31 outfile.write('/>\n')32 def exportAttributes(self, outfile, level, already_processed, namespace_='', name_='coord'):33 if self.y is not None and 'y' not in already_processed:34 already_processed.append('y')35 outfile.write(' %sy="%s"' % (namespace_,self.gds_format_float(self.y, input_name='y')))36 if self.x is not None and 'x' not in already_processed:37 already_processed.append('x')38 outfile.write(' %sx="%s"' % (namespace_,self.gds_format_float(self.x, input_name='x')))39 if self.z is not None and 'z' not in already_processed:40 already_processed.append('z')41 outfile.write(' %sz="%s"' % (namespace_,self.gds_format_float(self.z, input_name='z')))42 def exportChildren(self, outfile, level, namespace_='', name_='coord', fromsubclass_=False):43 pass44 def hasContent_(self):45 if (46 ):47 return True48 else:49 return False50 def exportLiteral(self, outfile, level, name_='coord'):51 level += 152 self.exportLiteralAttributes(outfile, level, [], name_)53 if self.hasContent_():54 self.exportLiteralChildren(outfile, level, name_)55 def exportLiteralAttributes(self, outfile, level, already_processed, name_):...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!