def read_vars(userVariables): # for GrADs subprocess.call('export DISPLAY=:0.0', shell=True) graphVariables = variables.define_graph_variables() # ---------------------------------- end user inputs -------------------------------------- # Checks that inputs are ok try: if not os.path.exists(userVariables.DIRS['TRMMdirName']): print "Error: TRMM invalid path!" userVariables.DIRS['TRMMdirName'] = raw_input( "> Please enter the location to the raw TRMM netCDF files: \n") except: pass try: if not os.path.exists(userVariables.DIRS['CEoriDirName']): print "Error! MERG invalid path!" userVariables.DIRS['CEoriDirName'] = raw_input( "> Please enter the directory to the MERG netCDF files: \n") except: print "..." # Check validity of time while utils.valid_date(userVariables.startDateTime) != True: print "Invalid time entered for startDateTime!" while utils.valid_date(userVariables.endDateTime) != True: print "Invalid time entered for endDateTime!" # Check if all the files exisits in the MERG and TRMM directories entered test, _ = check_for_files(userVariables.DIRS['TRMMdirName'], userVariables.startDateTime, userVariables.endDateTime, 3, 'hour') if test is False: print "Error with files in the TRMM directory entered. Please check your files before restarting. " return test, userVariables.filelist = check_for_files( userVariables.DIRS['CEoriDirName'], userVariables.startDateTime, userVariables.endDateTime, 1, 'hour') if test is False: print "Error with files in the original MERG directory entered. Please check your files before restarting. " return # Create main directory and file structure for storing intel userVariables.DIRS['mainDirStr'] = create_main_directory( userVariables.DIRS['mainDirStr']) TRMMCEdirName = userVariables.DIRS['mainDirStr'] + '/TRMMnetcdfCEs' CEdirName = userVariables.DIRS['mainDirStr'] + '/MERGnetcdfCEs' return graphVariables
def check_times(self, startDateTime, endDateTime): ''' Purpose:: check the times ''' #check validity of time while utils.valid_date(startDateTime) != True: print "Invalid time entered for startDateTime!" while utils.valid_date(endDateTime) != True: print "Invalid time entered for endDateTime!" if (float(startDateTime) > float(endDateTime)): print "Bad start and end times input! Check the config file. Now using default variables..." return False return True
def check_times(self, startDateTime, endDateTime): ''' Purpose:: check the times ''' # Check validity of time while utils.valid_date(startDateTime) != True: print "Invalid time entered for startDateTime!" while utils.valid_date(endDateTime) != True: print "Invalid time entered for endDateTime!" if (float(startDateTime) > float(endDateTime)): print "Bad start and end times input! Check the config file. Now using default variables..." return False return True
def read_vars(userVariables): # for GrADs subprocess.call('export DISPLAY=:0.0', shell=True) graphVariables = variables.define_graph_variables() # ---------------------------------- end user inputs -------------------------------------- # Checks that inputs are ok try: if not os.path.exists(userVariables.DIRS['TRMMdirName']): print "Error: TRMM invalid path!" userVariables.DIRS['TRMMdirName'] = raw_input("> Please enter the location to the raw TRMM netCDF files: \n") except: pass try: if not os.path.exists(userVariables.DIRS['CEoriDirName']): print "Error! MERG invalid path!" userVariables.DIRS['CEoriDirName'] = raw_input("> Please enter the directory to the MERG netCDF files: \n") except: print "..." # Check validity of time while utils.valid_date(userVariables.startDateTime) != True: print "Invalid time entered for startDateTime!" while utils.valid_date(userVariables.endDateTime) != True: print "Invalid time entered for endDateTime!" # Check if all the files exisits in the MERG and TRMM directories entered test, _ = check_for_files(userVariables.DIRS['TRMMdirName'], userVariables.startDateTime, userVariables.endDateTime, 3, 'hour') if test is False: print "Error with files in the TRMM directory entered. Please check your files before restarting. " return test, userVariables.filelist = check_for_files(userVariables.DIRS['CEoriDirName'], userVariables.startDateTime, userVariables.endDateTime, 1, 'hour') if test is False: print "Error with files in the original MERG directory entered. Please check your files before restarting. " return # Create main directory and file structure for storing intel userVariables.DIRS['mainDirStr'] = create_main_directory(userVariables.DIRS['mainDirStr']) TRMMCEdirName = userVariables.DIRS['mainDirStr']+'/TRMMnetcdfCEs' CEdirName = userVariables.DIRS['mainDirStr']+'/MERGnetcdfCEs' return graphVariables
def main(): CEGraph = nx.DiGraph() prunedGraph = nx.DiGraph() MCCList =[] MCSList=[] MCSMCCNodesList =[] allMCSsList =[] allCETRMMList =[] DIRS={} #for GrADs subprocess.call('export DISPLAY=:0.0', shell=True) #for first time working with the raw MERG zipped files # rawMERG = "/directory/to/the/raw/MERGfiles" # utils.preprocessing_merg(rawMERG) # --------------------------------------------------------------------------------- # ---------------------------------- user inputs -------------------------------------- DIRS['mainDirStr'] = "/home/meldefon/Studies/JPLGraphs/testSeparate"#"/directory/to/where/to/store/outputs" # BASELINE DATA + DATES DIRS['TRMMdirName'] = "/home/meldefon/Studies/JPLGraphs/grab-tag-graph/baselinDataDir/datadir/TRMM"#"/directory/to/the/TRMM/netCDF/files" DIRS['CEoriDirName'] = "/home/meldefon/Studies/JPLGraphs/grab-tag-graph/baselinDataDir/datadir/MERG"#"/directory/to/the/MERG/netCDF/files" #get the dates for analysis startDateTime = "200908310000" #"yyyymmddhrmm" endDateTime = "200908312100" # PAPER DATA + DATES DIRS['TRMMdirName'] = "/home/meldefon/Studies/JPLGraphs/grab-tag-graph/paperData/paperData/TRMM"#"/directory/to/the/TRMM/netCDF/files" DIRS['CEoriDirName'] = "/home/meldefon/Studies/JPLGraphs/grab-tag-graph/paperData/paperData/MERG"#"/directory/to/the/MERG/netCDF/files" #get the dates for analysis startDateTime = "200609110000" #"yyyymmddhrmm" endDateTime = "200609121200" # ---------------------------------- end user inputs -------------------------------------- # Checks that inputs are ok try: if not os.path.exists(DIRS['CEoriDirName']): print "Error! MERG invalid path!" DIRS['CEoriDirName'] = raw_input("> Please enter the directory to the MERG netCDF files: \n") except: print "..." try: if not os.path.exists(DIRS['TRMMdirName']): print "Error: TRMM invalid path!" DIRS['TRMMdirName'] = raw_input("> Please enter the location to the raw TRMM netCDF files: \n") except: pass try: if not os.path.exists(DIRS['CEoriDirName']): print "Error! MERG invalid path!" DIRS['CEoriDirName'] = raw_input("> Please enter the directory to the MERG netCDF files: \n") except: print "..." #check validity of time while utils.valid_date(startDateTime) != True: print "Invalid time entered for startDateTime!" while utils.valid_date(endDateTime) != True: print "Invalid time entered for endDateTime!" #check if all the files exisits in the MERG and TRMM directories entered test,_ = iomethods.check_for_files(DIRS['TRMMdirName'], startDateTime, endDateTime, 3, 'hour') if test == False: print "Error with files in the TRMM directory entered. Please check your files before restarting. " return #test,filelist = iomethods.check_for_files(startDateTime, endDateTime, DIRS['CEoriDirName'],1) test,filelist = iomethods.check_for_files(DIRS['CEoriDirName'], startDateTime, endDateTime, 1, 'hour') if test == False: print "Error with files in the original MERG directory entered. Please check your files before restarting. " return # end checks # create main directory and file structure for storing intel DIRS['mainDirStr'] = iomethods.create_main_directory(DIRS['mainDirStr']) TRMMCEdirName = DIRS['mainDirStr']+'/TRMMnetcdfCEs' CEdirName = DIRS['mainDirStr']+'/MERGnetcdfCEs' unittestFile = open(DIRS['mainDirStr']+'/unittestResults.txt','wb') unittestFile.write("\n Timing results for "+startDateTime+" to "+endDateTime) #let's go! # time how long it takes to complete reading in the data print "\n Start the timer " starttime = time.time() print "\n -------------- Read MERG Data ----------" print "\n Start the timer for the data ingest process" readMergStart = time.time() mergImgs, timeList, LAT, LON = iomethods.read_data(DIRS['CEoriDirName'],'ch4','latitude','longitude', filelist) readMergEnd = time.time() print "\n End the timer for the data ingest process" print "\n Total time to complete data ingest is %g seconds"%(readMergEnd - readMergStart) unittestFile.write("\n 1. Total time to complete data ingest is %g seconds"%(readMergEnd - readMergStart)) print ("-"*80) print "\n -------------- TESTING findCloudElements ----------" print "\n Start the timer for findCloudElements process" findCEsStart = time.time() # ********* EITHER ********* print "\n Using both MERG and TRMM simultaneously " #CEGraph = mccSearch.find_cloud_elements(mergImgs,timeList,DIRS['mainDirStr'], LAT,LON,DIRS['TRMMdirName']) CEGraph = mccSearch.par_find_cloud_elements(mergImgs,timeList,DIRS['mainDirStr'], LAT,LON,DIRS['TRMMdirName']) findCEsEnd = time.time() #print "\n Number of cloud elements found is: ", CEGraph.number_of_nodes() print "\n End the timer for findCloudElements process" print "\n Total time to complete finding cloud elements is %g seconds"%(findCEsEnd - findCEsStart) #return unittestFile.write("\n 2. Total time to complete finding cloud elements is %g seconds"%(findCEsEnd - findCEsStart)) print ("-"*80) # #********* OR ******* # #timing each separately #CEGraph = mccSearch.find_cloud_elements(mergImgs,timeList,DIRS['mainDirStr'], LAT,LON) #findCEsEnd = time.time() #print "\n End the timer for findCloudElements process using MERG only" #print "\n Total time to complete finding cloud elements in MERG only is %g seconds"%(findCEsEnd - findCEsStart) #unittestFile.write("\n Total time to complete finding cloud elements in MERG only is %g seconds"%(findCEsEnd - findCEsStart)) #print "\n Start the timer for findCloudElements process using TRMM only" #findCETRMMStart = time.time() #allCETRMMList = mccSearch.find_precip_rate(DIRS['TRMMdirName'],timeList) #findCETRMMEnd = time.time() #print "\n End the timer for findCloudElements process using TRMM only" #print "\n Total time to complete finding cloud elements in TRMM only is %g seconds"%(findCETRMMEnd - findCETRMMStart) #unittestFile.write("\n Total time to complete finding cloud elements in TRMM only is %g seconds"%(findCEsEnd - findCEsStart)) #print "\n Number of cloud elements found is: ", CEGraph.number_of_nodes() #print "\n Total time to complete finding cloud elements is %g seconds"%(findCETRMMEnd - findCEsStart) #unittestFile.write("\n Total time to complete finding cloud elements is %g seconds"%(findCETRMMEnd - findCEsStart)) #print ("-"*80) print "\n -------------- TESTING findCloudClusters ----------" print "\n Start the timer for findCloudClusters process" findCloudClustersStart = time.time() prunedGraph = mccSearch.find_cloud_clusters(CEGraph) print "The number of nodes in the prunedGraph is: ", prunedGraph.number_of_nodes() findCloudClustersEnd = time.time() print "\n End the timer for the findCloudClusters process" print "\n Total time to complete finding the cloud clusters is %g seconds"%(findCloudClustersEnd - findCloudClustersStart) unittestFile.write("\n 3. Total time to complete finding the cloud clusters is %g seconds"%(findCloudClustersEnd - findCloudClustersStart)) print ("-"*80) print "\n -------------- TESTING findMCCs ----------" print "\n Start the timer for the findMCCs process" findMCCStart = time.time() MCCList,MCSList = mccSearch.find_MCC(prunedGraph) print "\n MCC List has been acquired ", len(MCCList) print "\n MCS List has been acquired ", len(MCSList) findMCCEnd = time.time() print "\n End the timer for the findMCCs process" print "\n Total time to complete finding the MCCs is %g seconds"%(findMCCEnd - findMCCStart) unittestFile.write("\n 4. Total time to complete finding the MCCs is %g seconds"%(findMCCEnd - findMCCStart)) print ("-"*80) #end the timer endtime = time.time() print ("*"*80) print "\n The entire evaluation took %g seconds to complete" %(endtime - starttime) unittestFile.write("\n The entire evaluation took %g seconds to complete" %(endtime - starttime)) unittestFile.write("\n ----------------------------------------------------------------") unittestFile.write("\n Number of cloud elements found is: %d"%CEGraph.number_of_nodes()) unittestFile.write("\n Number of edges (with the cloud elements) found is: %d"%CEGraph.number_of_edges()) unittestFile.write("\n The number of nodes in the prunedGraph is: %d" %prunedGraph.number_of_nodes()) unittestFile.write("\n The number of edges (with nodes) in the prunedGraph is: %d" %prunedGraph.number_of_edges()) unittestFile.write("\n MCC List has been acquired %d" %len(MCCList)) unittestFile.write("\n MCS List has been acquired %d" %len(MCSList)) # TODO: report the domain unittestFile.close()
def main(): CEGraph = nx.DiGraph() prunedGraph = nx.DiGraph() MCCList = [] MCSList = [] MCSMCCNodesList = [] allMCSsList = [] allCETRMMList = [] DIRS = {} # DIRS={ # mainDirStr= "/directory/to/where/to/store/outputs" # TRMMdirName = "/directory/to/the/TRMM/netCDF/files" # CEoriDirName = "/directory/to/the/MERG/netCDF/files" # } preprocessing = "" rawMERG = "" # for GrADs subprocess.call("export DISPLAY=:0.0", shell=True) print "Running MCCSearch ..... \n" DIRS["mainDirStr"] = raw_input("> Please enter working directory: \n") # This is where data created will be stored preprocessing = raw_input("> Do you need to preprocess the MERG files? [y/n]: \n") while preprocessing.lower() != "n": if preprocessing.lower() == "y": # get location for raw files rawMERG = raw_input("> Please enter the directory to the RAW MERG (.Z) files: \n") # run preprocessing utils.preprocessing_merg(rawMERG) continue elif preprocessing.lower() == "n": pass else: print "Error! Invalid choice " preprocessing = raw_input("> Do you need to preprocess the MERG files? [y/n]: \n") # get the location of the MERG and TRMM data DIRS["CEoriDirName"] = raw_input("> Please enter the directory to the MERG netCDF files: \n") try: if not os.path.exists(DIRS["CEoriDirName"]): print "Error! MERG invalid path!" DIRS["CEoriDirName"] = raw_input("> Please enter the directory to the MERG netCDF files: \n") except: print "..." DIRS["TRMMdirName"] = raw_input("> Please enter the location to the raw TRMM netCDF files: \n") try: if not os.path.exists(DIRS["TRMMdirName"]): print "Error: TRMM invalid path!" DIRS["TRMMdirName"] = raw_input("> Please enter the location to the raw TRMM netCDF files: \n") except: pass # get the dates for analysis startDateTime = raw_input("> Please enter the start date and time yyyymmddhrmm: \n") # check validity of time while utils.valid_date(startDateTime) != True: print "Invalid time entered for startDateTime!" startDateTime = raw_input("> Please enter the start date and time yyyymmddhrmm: \n") endDateTime = raw_input("> Please enter the end date and time yyyymmddhrmm: \n") while utils.valid_date(endDateTime) != True: print "Invalid time entered for endDateTime!" endDateTime = raw_input("> Please enter the end date and time yyyymmddhrmm: \n") # check if all the files exisits in the MERG and TRMM directories entered # test,_ = iomethods.check_for_files(startDateTime, endDateTime, DIRS['TRMMdirName'], 2) test, _ = iomethods.check_for_files(DIRS["TRMMdirName"], startDateTime, endDateTime, 3, "hour") if test == False: print "Error with files in the original MERG directory entered. Please check your files before restarting. " return # test,filelist = iomethods.check_for_files(startDateTime, endDateTime, DIRS['CEoriDirName'],1) test, filelist = iomethods.check_for_files(DIRS["CEoriDirName"], startDateTime, endDateTime, 1, "hour") if test == False: print "Error with files in the original TRMM directory entered. Please check your files before restarting. " return # create main directory and file structure for storing intel DIRS["mainDirStr"] = iomethods.create_main_directory(DIRS["mainDirStr"]) TRMMCEdirName = DIRS["mainDirStr"] + "/TRMMnetcdfCEs" CEdirName = DIRS["mainDirStr"] + "/MERGnetcdfCEs" # for doing some postprocessing with the clipped datasets instead of running the full program, e.g. postprocessing = raw_input("> Do you wish to postprocess data? [y/n] \n") while postprocessing.lower() != "n": if postprocessing.lower() == "y": option = postprocessing_plot_menu(DIRS) return elif postprocessing.lower() == "n": pass else: print "\n Invalid option." postprocessing = raw_input("> Do you wish to postprocess data? [y/n] \n") # ------------------------------------------------------------------------------------------------- # Getting started. Make it so number one! print ("-" * 80) print "\t\t Starting the MCCSearch Analysis " print ("-" * 80) print "\n -------------- Reading MERG and TRMM Data ----------" mergImgs, timeList, LAT, LON = iomethods.read_data(DIRS["CEoriDirName"], "ch4", "latitude", "longitude", filelist) print "\n -------------- findCloudElements ----------" CEGraph = mccSearch.find_cloud_elements(mergImgs, timeList, DIRS["mainDirStr"], LAT, LON, DIRS["TRMMdirName"]) # theList = CEGraph.successors(node) # if the TRMMdirName wasnt entered for whatever reason, you can still get the TRMM data this way # CEGraph = mccSearch.findCloudElements(mergImgs,timeList) # allCETRMMList=mccSearch.findPrecipRate(DIRS['TRMMdirName'],timeList) # ---------------------------------------------------------------------------------------------- print "\n -------------- findCloudClusters ----------" prunedGraph = mccSearch.find_cloud_clusters(CEGraph) print "\n -------------- findMCCs ----------" MCCList, MCSList = mccSearch.find_MCC(prunedGraph) # now ready to perform various calculations/metrics print ("-" * 80) print "\n -------------- METRICS ----------" print ("-" * 80) # some calculations/metrics that work that work print "creating the MCC userfile ", metrics.create_text_file(MCCList, 1, DIRS["mainDirStr"], 80000.0, 1) print "creating the MCS userfile ", metrics.create_text_file(MCSList, 2, DIRS["mainDirStr"], 80000.0, 1) plot_menu(MCCList, MCSList, DIRS) # Let's get outta here! Engage! print ("-" * 80)
def main(): sys.setrecursionlimit(5000) CEGraph = nx.DiGraph() prunedGraph = nx.DiGraph() MCCList =[] MCSList=[] MCSMCCNodesList =[] allMCSsList =[] allCETRMMList =[] DIRS={} #for GrADs subprocess.call('export DISPLAY=:0.0', shell=True) #for first time working with the raw MERG zipped files # rawMERG = "/directory/to/the/raw/MERGfiles" # utils.preprocessing_merg(rawMERG) # --------------------------------------------------------------------------------- # ---------------------------------- user inputs -------------------------------------- DIRS['mainDirStr'] = "/Users/kwhitehall/Documents/capstones/usc2015/baselineTimings/test"#"/directory/to/where/to/store/outputs" DIRS['TRMMdirName'] = "/Users/kwhitehall/Documents/capstones/usc2015/baselineTimings/datadir/TRMM"#"/directory/to/the/TRMM/netCDF/files" DIRS['CEoriDirName'] = "/Users/kwhitehall/Documents/capstones/usc2015/baselineTimings/datadir/MERG"#"/directory/to/the/MERG/netCDF/files" #get the dates for analysis startDateTime = "200908310000" #"yyyymmddhrmm" endDateTime = "200908312100" # ---------------------------------- end user inputs -------------------------------------- # Checks that inputs are ok try: if not os.path.exists(DIRS['CEoriDirName']): print "Error! MERG invalid path!" DIRS['CEoriDirName'] = raw_input("> Please enter the directory to the MERG netCDF files: \n") except: print "..." try: if not os.path.exists(DIRS['TRMMdirName']): print "Error: TRMM invalid path!" DIRS['TRMMdirName'] = raw_input("> Please enter the location to the raw TRMM netCDF files: \n") except: pass try: if not os.path.exists(DIRS['CEoriDirName']): print "Error! MERG invalid path!" DIRS['CEoriDirName'] = raw_input("> Please enter the directory to the MERG netCDF files: \n") except: print "..." #check validity of time while utils.valid_date(startDateTime) != True: print "Invalid time entered for startDateTime!" while utils.valid_date(endDateTime) != True: print "Invalid time entered for endDateTime!" #check if all the files exisits in the MERG and TRMM directories entered test,_ = iomethods.check_for_files(DIRS['TRMMdirName'], startDateTime, endDateTime, 3, 'hour') if test == False: print "Error with files in the TRMM directory entered. Please check your files before restarting. " return #test,filelist = iomethods.check_for_files(startDateTime, endDateTime, DIRS['CEoriDirName'],1) test,filelist = iomethods.check_for_files(DIRS['CEoriDirName'], startDateTime, endDateTime, 1, 'hour') if test == False: print "Error with files in the original MERG directory entered. Please check your files before restarting. " return # end checks # create main directory and file structure for storing intel DIRS['mainDirStr'] = iomethods.create_main_directory(DIRS['mainDirStr']) TRMMCEdirName = DIRS['mainDirStr']+'/TRMMnetcdfCEs' CEdirName = DIRS['mainDirStr']+'/MERGnetcdfCEs' # for doing some postprocessing with the clipped datasets instead of running the full program, e.g. # mccSearch.post_processing_netcdf(3,CEoriDirName) # mccSearch.post_processing_netcdf(2) # ------------------------------------------------------------------------------------------------- #let's go! print "\n -------------- Read MERG Data ----------" mergImgs, timeList, LAT, LON = iomethods.read_data(DIRS['CEoriDirName'],'ch4','latitude','longitude', filelist) print ("-"*80) print "\n -------------- TESTING findCloudElements ----------" CEGraph = mccSearch.find_cloud_elements(mergImgs,timeList,DIRS['mainDirStr'], LAT,LON,DIRS['TRMMdirName']) #if the TRMMdirName wasnt entered for whatever reason, you can still get the TRMM data this way # CEGraph = mccSearch.findCloudElements(mergImgs,timeList,DIRS['mainDirStr'], LAT,LON) # allCETRMMList=mccSearch.findPrecipRate(DIRS['TRMMdirName'],timeList) # ---------------------------------------------------------------------------------------------- print ("-"*80) print "number of nodes in CEGraph is: ", CEGraph.number_of_nodes() print ("-"*80) print "\n -------------- TESTING findCloudClusters ----------" prunedGraph = mccSearch.find_cloud_clusters(CEGraph) print ("-"*80) print "number of nodes in prunedGraph is: ", prunedGraph.number_of_nodes() print ("-"*80) #sys.exit() print "\n -------------- TESTING findMCCs ----------" MCCList,MCSList = mccSearch.find_MCC(prunedGraph) print ("-"*80) print "MCC List has been acquired ", len(MCCList) print "MCS List has been acquired ", len(MCSList) print ("-"*80) #now ready to perform various calculations/metrics print "\n -------------- TESTING METRICS ----------" #some calculations/metrics that work that work # print "creating the MCC userfile ", metrics.createTextFile(MCCList,1) # print "creating the MCS userfile ", metrics.createTextFile(MCSList,2) # MCCTimes, tdelta = metrics.temporalAndAreaInfoMetric(MCCList) # print "number of MCCs is: ", metrics.numberOfFeatures(MCCList) # print "longest duration is: ", metrics.longestDuration(MCCTimes), "hrs" # print "shortest duration is: ", metrics.shortestDuration(MCCTimes), "hrs" # print "Average duration is: ", metrics.averageDuration(MCCTimes), "hrs" # print "Average size is: ", mmetrics.averageFeatureSize(MCCList), "km^2" #some plots that work # plotting.plotAccTRMM(MCCList) # plotting.displayPrecip(MCCList) # plotting.plotAccuInTimeRange('yyyy-mm-dd_hh:mm:ss', 'yyyy-mm-dd_hh:mm:ss') # plotting.displaySize(MCCList) # plotting.displayPrecip(MCCList) # plotting.plotHistogram(MCCList) # print ("-"*80)
def test_poor_date_format(self): longDate = "2015-01-03 12:00" self.assertFalse(utils.valid_date(longDate))
def test_good_input_hours_minutes(self): goodHoursMinutes = "201501010059" self.assertTrue(utils.valid_date(goodHoursMinutes))
def test_good_input_hours_only(self): goodDatetime = "2015010100" self.assertTrue(utils.valid_date(goodDatetime))
def test_bad_hour(self): badHour = "2015010124" self.assertFalse(utils.valid_date(badHour))
def test_bad_month(self): badMonth = "2015000100" self.assertFalse(utils.valid_date(badMonth))
def test_short_date_string(self): shortDate = "20150101" self.assertFalse(utils.valid_date(shortDate))
def test_valid_date(self): date = '2010-10-10' expected_date = datetime.strptime(date, "%Y-%m-%d") self.assertEqual(expected_date, valid_date(date)) with self.assertRaises(argparse.ArgumentTypeError): valid_date('1')