Пример #1
0
    def test_vcs_datetime(self):
        """
        This is basically testing the datetime.datetime() function that is
        called from parseVcsTimeFormat()
        """

        with self.assertRaises(ValueError):
            # Checks if datetime.datetime() raises a value error on not a date
            dateparser.parseVcsTimeFormat("20121313T071000Z") # Not a date

        with self.assertRaises(TypeError):
            # Checks if datetime.datetime() raises a type error on wrong type
            datetime.datetime(2012, "test", 13, 7, 10, 0, 0)
Пример #2
0
def eventMakeObject(event, datechoice):
	event = event.split("\n")
	objArray = []
	eventDict = {}
	for each in event:
		if re.match("(?:DTSTART)(.*?)", each): # Find start time
			dtstart 	= each.replace("DTSTART:", "") # Remove non-relevant info
			startTime 	= dateparser.parseVcsTimeFormat(dtstart) # Parse to datetime
			eventDict['startTime'] 	= startTime
		elif re.match("(?:DTEND)(.*?)", each): # Find end time
			dtend 		= each.replace("DTEND:", "") # Remove non-relevant info
			endTime		= dateparser.parseVcsTimeFormat(dtend) # Parse to datetime
			eventDict['endTime']	= endTime
		elif re.match("(?:SUMMARY)(.*?)", each): # Find the SUMMARY-property
			summary = each.split(":") # Split SUMMARY on each comma
			classProperty = summary[1] # Second part of the summary is the class-property
			classProperty = classProperty.replace(" ", "") # Remove spaces
			classProperty = classProperty.split(",") # Split on comma
			classInsert = []
			for each in classProperty:
				if int(each) in classList():
					classURL = '<a href="' + url_for("class_choice", classchoice=int(each)) + '">' \
					+ each + '</a>'
					classInsert.append(classURL)
				else:
					classInsert.append(each)
			eventDict['class']		= ", ".join(classInsert)
			eventDict['teacher']	= summary[2] # 
			eventDict['subject']	= summary[3] # 
			if len(summary) > 4:
				eventDict['subjectID']	= summary[4]
			else:
				eventDict['subjectID']	= None
			if len(summary) > 5:
				eventDict['comment']	= summary[5]
			else:
				eventDict['comment']	= None
		elif re.match("(?:LOCATION)(.*?)", each): # Find the LOCATION-property
			eventDict['location']	= each.replace("LOCATION;ENCODING=QUOTED-PRINTABLE:", "")
	if eventDict['startTime'].date() == datechoice:
		return eventDict
	else:
		return None
Пример #3
0
    def test_vcs_conversion(self):
        """
        Test for testing the VCS timeformat conversion.

        This tests passes if the valid string 20121213T071000Z is equal to the 
        expected datetime format when parsed through the 
        parseVcsTimeFormat-function.
        
        Observer - the parse Vcs TimeFormat changes the hour from UTC -> CET
        """
        testDataVcs = "20121213T071000Z"
        testDataTime = datetime.datetime(2012, 12, 13, 8, 10, 0, 0)

        test = dateparser.parseVcsTimeFormat(testDataVcs)    

        testDataVcs2 = "20120913T061000Z"
        testDataTime2 = datetime.datetime(2012, 9, 13, 8, 10, 0, 0)

        test2 = dateparser.parseVcsTimeFormat(testDataVcs2)    

        self.assertEqual(test, testDataTime)
        self.assertEqual(test2, testDataTime2)
Пример #4
0
    def test_vcs_wrong_format(self):
        """
        Test for the VCS timeformat conversion.

        This test passes if all of the invalid inputs  raises the expected
        exception when parsed to parseVcsTimeFormat.
        """

        with self.assertRaisesRegexp(ValueError, 'Empty'):
            # Tries if empty strings raises the empty-exception.
            dateparser.parseVcsTimeFormat("")

        with self.assertRaisesRegexp(TypeError, 'Wrong type'):
            # Tests if non-strings raises the wrong type-exception.
            dateparser.parseVcsTimeFormat(["12", "12", "13", "07", "10"])
            dateparser.parseVcsTimeFormat(15)

        with self.assertRaisesRegexp(ValueError, 'Swapped'):
            # Swapped place of Z and T
            dateparser.parseVcsTimeFormat("20121213Z071000T") # Z and T swapped

        with self.assertRaises(Exception):
            # Tests if a few other inputs raises the Unknown error-exception.
            dateparser.parseVcsTimeFormat("19940226 15:00") # Wrong datetime