本文整理汇总了Python中Twitter_Utils.EternalProcess.EternalProcess.check_if_stream_should_end方法的典型用法代码示例。如果您正苦于以下问题:Python EternalProcess.check_if_stream_should_end方法的具体用法?Python EternalProcess.check_if_stream_should_end怎么用?Python EternalProcess.check_if_stream_should_end使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Twitter_Utils.EternalProcess.EternalProcess
的用法示例。
在下文中一共展示了EternalProcess.check_if_stream_should_end方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestEternalProcess
# 需要导入模块: from Twitter_Utils.EternalProcess import EternalProcess [as 别名]
# 或者: from Twitter_Utils.EternalProcess.EternalProcess import check_if_stream_should_end [as 别名]
class TestEternalProcess(unittest.TestCase):
def test___init__(self):
assert True
def setUp(self):
self.eternalProcess = EternalProcess()
self.stream_list = []
self.end_times_list = []
self.time_to_check_games_for_the_day = '09:30'
self.data_gatherer = DataGatherer()
def test_check_if_stream_should_end(self):
# Shouldn't end if there is no stream
self.assertEqual(False, self.eternalProcess.check_if_stream_should_end())
# Should end if there is a stream
self.eternalProcess.end_times_list.append(datetime.datetime.now().strftime('%H:%M'))
stream = self.data_gatherer.get_tweet_stream('ok', '123', '123')
self.eternalProcess.stream_list.append(stream)
self.assertEqual(True, self.eternalProcess.check_if_stream_should_end())
def test_get_time_to_end_stream(self):
eternal_process = EternalProcess()
now = datetime.datetime.now()
now_plus_10 = now + datetime.timedelta(minutes=10)
now_plus_10 = now_plus_10.strftime('%H:%M')
self.assertEqual(now_plus_10, eternal_process.get_time_to_end_stream(10))
def test_get_write_path_for_days_games(self):
eternal_process = EternalProcess()
base = os.getcwd() + '/Twitter_Utils/data/daily-logs/'
end = datetime.datetime.now().strftime('%Y-%m-%d') + '.json'
self.assertEqual(base + end, eternal_process.get_write_path_for_days_games())
def test_is_time_to_get_game_data_for_day(self):
eternal_process = EternalProcess()
eternal_process.time_to_check_games_for_the_day = datetime.datetime.now().strftime('%H:%M')
self.assertEqual(True, eternal_process.is_time_to_get_game_data_for_day())
eternal_process.time_to_check_games_for_the_day = '04:14'
self.assertEqual(False, eternal_process.is_time_to_get_game_data_for_day())
def test_write_days_games_data(self):
assert True
def test_sleep_for(self):
assert True
示例2: TestEternalProcess
# 需要导入模块: from Twitter_Utils.EternalProcess import EternalProcess [as 别名]
# 或者: from Twitter_Utils.EternalProcess.EternalProcess import check_if_stream_should_end [as 别名]
class TestEternalProcess(unittest.TestCase):
def test___init__(self):
assert True
def setUp(self):
self.eternalProcess = EternalProcess()
self.stream_list = []
self.end_times_list = []
self.time_to_check_games_for_the_day = '09:30'
self.data_gatherer = DataGatherer()
self.time_now = datetime.datetime.now()
path = self.eternalProcess.base_path + self.time_now.strftime('%Y-%m-%d') + '.json'
fo = open(path, 'w+')
fo.write('[{"uuid": "4b2fb0bc-864c-4ede-be61-59ed14e1da50", "title": "Spurs vs Clippers",'
'"start_time": "2016-02-18T17:18:00-08:00", "being_streamed": true, "home_team_id":'
'"5bf2300f-777b-4caa-9ef3-3fda11f17ad1", "away_team_id": "ed803cc0-8e6e-4798-b5aa-9eecbc977801",'
'"slug": "nba-2015-2016-sa-lac-2016-02-18-1930"}]')
fo.close()
# register remove function
self.addCleanup(os.remove, path)
dir_path = os.getcwd() + '/Twitter_Utils/data/tweets/base_tweets_for_tests'
if not os.path.exists(dir_path):
os.makedirs(dir_path)
self.addCleanup(os.rmdir, dir_path)
self.path_2 = os.getcwd() + '/Twitter_Utils/data/tweets/base_tweets_for_tests/base_tweets_for_tests.txt'
fo = open(self.path_2, 'w+')
fo.write('test tweet 1\ntest tweet 1\ntest tweet 1\ntest tweet 1\ntest tweet 2\ntest tweet 2\ntest tweet 2\n')
fo.close()
self.addCleanup(os.remove, self.path_2)
def test_check_if_stream_should_end(self):
# Shouldn't end if there is no stream
self.assertEqual(False, self.eternalProcess.check_if_stream_should_end())
# Should end if there is a stream
self.eternalProcess.end_times_list.append(datetime.datetime.now().strftime('%H:%M'))
self.eternalProcess.game_name_list.append('2016-03-05-Pacers-vs-Wizards')
keywords = 'TrueToAtlanta,TrueToAtlanta,ATL,Hawks,DennisSchroder,ThaboSefolosha,' \
'TimHardawayJr.,PaulMillsap,MikeScott,JeffTeague,MikeMuscala,KyleKorver,' \
'AlHorford,KentBazemore,goTrueToAtlanta,goTrueToAtlanta,goATL,goHawks,' \
'goDennisSchroder,goThaboSefolosha,goTimHardawayJr.,goPaulMillsap,goMikeScott,' \
'goJeffTeague,goMikeMuscala,goKyleKorver,goAlHorford,goKentBazemore,' \
'Dennis Schroder,Thabo Sefolosha,Tim Hardaway Jr.,Paul Millsap,Mike Scott,' \
'Jeff Teague,Mike Muscala,Kyle Korver,Al Horford,Kent Bazemore' \
'---Celtics,Celtics,Celtics,CotyClarke,IsaiahThomas,JamesYoung,AveryBradley,' \
'TerryRozier,EvanTurner,JordanMickey,MarcusSmart,JaredSullinger,KellyOlynyk,' \
'TylerZeller,R.J.Hunter,AmirJohnson,JonasJerebko,goCeltics,goCeltics,goCeltics,' \
'goCotyClarke,goIsaiahThomas,goJamesYoung,goAveryBradley,goTerryRozier,goEvanTurner,' \
'goJordanMickey,goMarcusSmart,goJaredSullinger,goKellyOlynyk,goTylerZeller,' \
'goR.J.Hunter,goAmirJohnson,goJonasJerebko,Coty Clarke,Isaiah Thomas,James Young,' \
'Avery Bradley,Terry Rozier,Evan Turner,Jordan Mickey,Marcus Smart,Jared Sullinger,' \
'Kelly Olynyk,Tyler Zeller,R.J. Hunter,Amir Johnson,Jonas Jerebko'
stream = self.data_gatherer.get_tweet_stream(keywords, '123', '2016-03-05-Pacers-vs-Wizards')
self.eternalProcess.stream_list.append(stream)
self.assertEqual(True, self.eternalProcess.check_if_stream_should_end())
def test_check_if_stream_should_end_should_return_false_if_none(self):
now = datetime.datetime.now()
now_plus_10 = now + datetime.timedelta(minutes=10)
now_plus_10 = now_plus_10.strftime('%H:%M')
self.eternalProcess.end_times_list.append(now_plus_10)
self.assertEqual(False, self.eternalProcess.check_if_stream_should_end())
def test_get_time_to_end_stream(self):
now = datetime.datetime.now()
eternal_process = EternalProcess()
now_plus_10 = now + datetime.timedelta(minutes=10)
now_plus_10 = now_plus_10.strftime('%H:%M')
self.assertEqual(now_plus_10, eternal_process.get_time_to_end_stream(10))
def test_get_write_path_for_days_games(self):
eternal_process = EternalProcess()
wd = os.getcwd()
pos = wd.find("BigDataMonsters")
if pos > 0: # pragma: no cover
path = wd[0:pos+15]
else:
path = wd
base = path + '/Twitter_Utils/data/daily-logs/'
end = datetime.datetime.now().strftime('%Y-%m-%d') + '.json'
self.assertEqual(base + end, eternal_process.get_write_path_for_days_games())
def test_is_time_to_get_game_data_for_day(self):
eternal_process = EternalProcess()
eternal_process.time_to_check_games_for_the_day = datetime.datetime.now().strftime('%H:%M')
self.assertEqual(True, eternal_process.is_time_to_get_game_data_for_day())
eternal_process.time_to_check_games_for_the_day = '04:14'
self.assertEqual(False, eternal_process.is_time_to_get_game_data_for_day())
def test_sleep_for(self):
eternal_process = EternalProcess()
time_now = datetime.datetime.now()
eternal_process.sleep_for(1, time.time())
time_now_plus_1 = datetime.datetime.now().strftime('%H:%M:%S')
time_now += datetime.timedelta(seconds=1)
time_now = time_now.strftime('%H:%M:%S')
self.assertEqual(time_now, time_now_plus_1)
#.........这里部分代码省略.........