def test_dateregex_multifile(self): self._delete_target_file() _create_random_regex_date_file(100, 10000, self.__DATAFILE__) _create_random_regex_date_file(100, 10000, self.__DATAFILE2__) data = self.sorter.sort_file("./", file_pattern="testData.*\\.log", comp=compare_date('%Y-%m-%d %H:%M:%S.%f', parser_regex(RE_D56, 0)), memory_safe=True, max_men=5000000) prev_line = None size = 0 for line in data: size += 1 if prev_line: self.assertLessEqual( datetime.datetime.strptime( re.search(RE_D5, prev_line).groups()[0], '%Y-%m-%d %H:%M:%S.%f'), datetime.datetime.strptime( re.search(RE_D5, line).groups()[0], '%Y-%m-%d %H:%M:%S.%f')) prev_line = line self.assertEqual(size, 20000)
def test_date_regex_no_file(self): self.__delete_target_file() _create_random_regex_date_file(100, 10000, self.__DATAFILE__) data = self.sorter.sort_file(self.__DATAFILE__, comp=compare_date('%Y-%m-%d %H:%M:%S.%f', parser_regex(RE_D6, 0))) prev_line = None for line in data: if prev_line: self.assertLessEqual( datetime.strptime( re.search(RE_D5, prev_line).groups()[0], '%Y-%m-%d %H:%M:%S.%f'), datetime.strptime( re.search(RE_D5, line).groups()[0], '%Y-%m-%d %H:%M:%S.%f')) prev_line = line
def test_date_regex_no_file(self): self._delete_target_file() _create_random_regex_date_file(100, 10000, self.__DATAFILE__) data = self.sorter.sort_file(self.__DATAFILE__, comp=compare_date('%Y-%m-%d %H:%M:%S.%f', parser_regex(RE_D56, 0)), memory_safe=True, max_men=5000000) prev_line = None for line in data: if prev_line: self.assertTrue( datetime.datetime.strptime( re.search(RE_D5, prev_line).groups()[0], '%Y-%m-%d %H:%M:%S.%f') <= datetime.datetime.strptime( re.search(RE_D5, line).groups()[0], '%Y-%m-%d %H:%M:%S.%f')) prev_line = line
def test_date_regex(self): self.__delete_target_file() _create_random_regex_date_file(100, 10000, self.__DATAFILE__) self.sorter.sort_file(self.__DATAFILE__, dst_file=self.__TARGETFILE__, comp=compare_date('%Y-%m-%d %H:%M:%S.%f', parser_regex(RE_D6, 0))) with open(self.__TARGETFILE__, 'r') as file: prev_line = file.readline() while prev_line: line = file.readline() if line: self.assertLessEqual( datetime.strptime( re.search(RE_D5, prev_line).groups()[0], '%Y-%m-%d %H:%M:%S.%f'), datetime.strptime( re.search(RE_D5, line).groups()[0], '%Y-%m-%d %H:%M:%S.%f')) prev_line = line
def test_dateregex(self): self._delete_target_file() _create_random_regex_date_file(100, 10000, self.__DATAFILE__) self.sorter.sort_file(self.__DATAFILE__, self.__TARGETFILE__, comp=compare_date('%Y-%m-%d %H:%M:%S.%f', parser_regex(RE_D56, 0)), memory_safe=True, max_men=5000000) with open(self.__TARGETFILE__, 'r') as file: prev_line = file.readline() while prev_line: line = file.readline() if line: self.assertTrue( datetime.datetime.strptime( re.search( RE_D5, prev_line).groups()[0], '%Y-%m-%d %H:%M:%S.%f') <= datetime.datetime.strptime( re.search( RE_D5, line).groups()[0], '%Y-%m-%d %H:%M:%S.%f')) prev_line = line