def test_good_day16(self): rdict = {'date': "2000 02 29.333333"} try: checkDate(rdict) except RuntimeError: pytest.fail("Unexpected raise of RuntimeError")
def test_bad_day6(self): rdict = {'date': "1800 01 01.333 "} with pytest.raises(RuntimeError) as e_info: data = checkDate(rdict) assert self.expected_message2 % (rdict['date'], rdict['date']) == str( e_info.value)
def parse_dataline(line): """ Parse a line of MPC1992 80 column format and return a dictionary of decoded values. Parameters ---------- line: str An 80 column line in MPC1992 format Returns ------- ret: dict A dictionary of parsed parameters as key/value pairs. Raises ------ error80(RuntimeError): Raised if there is a problem parsing the line (usually too long/trailing whitespace) or a problem decoding one of the individual fields. Notes ----- This is a cut-down version of the `ADES_Master.mpc80coltoxml.decode80ColumnDataLine` that only supports the optical line format (since Astrometrica cannot produce radar, roving observer or satellite format lines) """ # # matches optical line; also V and S and X # # groups: first seven are for all types # 1: id group # 2: discovery # 3: notes -- notes can be anything; valid Notes is wrong # 4: codes and RvSsVvXx # 5: yyyy from obsDate # 6: blank or a-e for asteroid satellites (embedded in obsDat) # 7: rest of obsDate commonRegexHelp1 = ('([A-za-z0-9 ]{12})' # id group 1-12 + '([ *+])' # discovery group 13 may be ' ', '*' or '+' #+ '( AaBbcDdEFfGgGgHhIiJKkMmNOoPpRrSsTtUuVWwYyCQX2345vzjeL16789])' # notes group 14 + '(.)' # notes can be anything ) commonRegexHelp2 = (r'(\d{4})' # yyyy from obsDate 16-19 + '([ a-e])' # asteroid satellite embedded in date 20 + '([0-9 .]{12})' # rest of obsDate loosely checked 21-32 ) # ----------- remainder depends on type. This is for optical and SV # 8: Ra # 9: Dec # 10: doc says blank but stuff is here # 11: mag # 12: band # 13: packedref and astCode as first character # 14: 3-character obs stn code # normalLineRegex = re.compile(('^' + commonRegexHelp1 + '([A PeCTMcEOHNn])' # codes group -- do not include RrSsVvXx 15 + commonRegexHelp2 + '([0-9 .]{12})' # Ra loosely checked 33-44 + '([-+ ][0-9 .]{11})' # Dec loosely checked 45-56 + '(.{9})' # mpc doc says blank but not 57-65 + '(.{5})' # mag 66-70 + '(.{1})' # band 71 + '(.{6})' # packedref 72-77. 72 by itself is astCode + '(.{3})' # obs stn 78-80 + '$') ) ret = {} if not line: return ret if len(line) > 80: error80(repr(len(line)) + ' columns', line) ret['subFmt'] = 'M92' # since were are MPC 80-col format m = normalLineRegex.match(line) # optical, SVXx if m: # print (m.groups()) ret['totalid'] = m.group(1) ret['disc'] = m.group(2) ret['notes'] = m.group(3) ret['code'] = m.group(4) ret['date'] = m.group(5) + m.group(6) + m.group(7) ret['raSexagesimal'] = m.group(8) ret['decSexagesimal'] = m.group(9) ret['bl1'] = m.group(10) ret['mag'] = m.group(11) ret['band'] = m.group(12) ret['packedref'] = m.group(13) ret['stn'] = m.group(14) sexVals.checkDate(ret) # check date first sexVals.checkRa(ret) sexVals.checkDec(ret) else: error80("no match for line", line) # # more value sanity checks # sexVals.checkDate(ret) # check date always if ret['code'] not in packUtil.validCodes: error80("invalid column 14 " + ret['code']+ " in line ", line) else: ret['mode'] = packUtil.codeDict[ret['code']] # No mapping of program codes yet ret['prog'] = ' ' if ret['notes'] not in packUtil.validNotes: error80("invalid note "+ ret['notes'] +" in line ", line) # Determine catalog code; 72 - first in packed reference. Blank for submissions ret['astCat'] = ret['packedref'][0] # # compute unpacked ID fields. This may be only a trkSub # (permID, provID, trkSub) = packUtil.unpackPackedID(ret['totalid']) ret['permID'] = permID ret['provID'] = provID ret['trkSub'] = trkSub #print(permID, provID, trkSub) try: packtest = packUtil.packTupleID((permID, provID, trkSub)) if packtest != ret['totalid']: print ("ID does not round-trip; " + packtest + " vs. " + ret['totalid']) except RuntimeError: print ("fails pack: ", permID, provID, trkSub) return ret
def test_bad_month3(self): rdict = {'date': "1920 13 01.3333333"} with pytest.raises(RuntimeError) as e_info: data = checkDate(rdict) assert self.expected_message + rdict['date'] == str(e_info.value)
def test_bad_day12(self): rdict = {'date': "2019 02 29.333333"} with pytest.raises(RuntimeError) as e_info: data = checkDate(rdict) assert self.expected_message3 + rdict['date'] == str(e_info.value)