class TestWatcher(ParametrizedTestCase): def setUp(self): self.w = Watcher(self.settings) def test_load_exchanges(self): self.assertEqual(set(self.settings["exchanges"]), set(self.w.exchanges.keys())) def test_find_trade(self): self.w.find_trade()
ROOT_INSTALL_PATH = os.path.abspath(os.path.join(dir_current, "..")) FILENAME_SETTINGS_MAINNET = os.path.join(ROOT_INSTALL_PATH, 'src/data/protocol.mainnet.json') FILENAME_SETTINGS_TESTNET = os.path.join(ROOT_INSTALL_PATH, 'src/data/protocol.testnet.json') FILENAME_SETTINGS_PRIVNET = os.path.join(ROOT_INSTALL_PATH, 'src/data/protocol.privnet.json') FILENAME_SETTINGS_COZNET = os.path.join(ROOT_INSTALL_PATH, 'src/data/protocol.coz.json') # Logfile default settings (only used if --logfile arg is used) LOGFILE_MAX_BYTES = 5e7 # 50 MB LOGFILE_BACKUP_COUNT = 3 # 3 logfiles history # Set the PID file, possible to override with env var PID_FILE PID_FILE = os.getenv("PID_FILE", "/tmp/neopython-api-server.pid") # init watcher Watcher.newInstance() def write_pid_file(): """ Write a pid file, to easily kill the service """ with open(PID_FILE, "w") as f: f.write(str(os.getpid())) def custom_background_code(): """ Custom code run in a background thread. This function is run in a daemonized thread, which means it can be instantly killed at any moment, whenever the main thread quits. If you need more safety, don't use a daemonized thread and handle exiting this thread in another way (eg. with signals and events). """
def setUp(self): self.w = Watcher(self.settings)
my_reconstructed = reconstructed_matrix[chosen].values my_contribution = contribution_matrix[chosen].values # Initialize fireworks display for the first input column diameter_max = 100 diameter_min = 15 myDisplay = fireworks.Display(firework_count=15, dimensions=30, dimension_min=0, dimension_max=1000, diameter_min=15, diameter_max=100, spark_min=10, spark_max=50, gaussian_spark_count=10, fitness_function=fitness.fitness_manhattan_similarity_sum, catalog=my_catalog, mutational_data=my_input, spark_dimension_count=10, dimension_limit=False) myDisplay.create_fireworks(None) myDisplay.showtime() watcher = Watcher(iterations=15, threshold=0.001, starting_iteration=10, fw_display=myDisplay) watcher.iterate(for_range=range(0, 200), reduction=0.99) logging.info("Finished iterating. Comparing solutions.") new_reconstructed = np.dot(np.array(my_catalog), np.array(myDisplay.best_spark.position)) FW_result = np.average(paired_distances( np.array(new_reconstructed).reshape(-1, 1), np.array(my_input).reshape(-1, 1), metric='manhattan')) MP_result = np.average(paired_distances( np.array(my_reconstructed).reshape(-1, 1), np.array(my_input).reshape(-1, 1), metric='manhattan')) FW_result2 = np.average(paired_distances( np.array(new_reconstructed).reshape(1, -1), np.array(my_input).reshape(1, -1), metric='cosine')) MP_resul2 = np.average(paired_distances( np.array(my_reconstructed).reshape(1, -1), np.array(my_input).reshape(1, -1), metric='cosine'))
from logging import getLogger, INFO, basicConfig logger = getLogger(__name__) format_ = "[%(asctime)s]:%(filename)s:%(lineno)s:%(message)s" basicConfig(format=format_, level=INFO, filename="c4N4Re.log", filemode='w') if __name__ == "__main__": config = ConfigParser() config.read("config.ini") if (not config.has_section("login") or not config.has_option("login", "email") or not config.has_option("login", "app_pass")): login = Login(config=config) try: login.env_login() except: logger.critical( "Unable to retrieve email or app password values from config file." ) try: watcher = Watcher(config=config) watcher.watch() except KeyboardInterrupt: logger.info("Captured KeyboardInterrupt exception. Exiting program") exit(1) except Exception as e: logger.critical(f"Exception -> {e}") exit(1)
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) faces = face_detector.detectMultiScale(gray, 1.3, 5) for (x, y, w, h) in faces: cv2.rectangle(gray, (x, y), (x + w, y + h), (255, 0, 0), 2) count += 1 dir1 = os.path.join(dir, face_id) if not os.path.exists(dir1): os.makedirs(dir1) # Save the captured image into the datasets folder cv2.imwrite(dir1 + "/" + str(count) + ".jpg", gray[y:y + h, x:x + w]) cv2.imshow('frame', gray) if count >= 10: print("10 face sample and stop dataset") break else: break capt.release() cv2.destroyAllWindows() encode_faces.encoding() print("encoded images") def custom_action(): capture_encode_faces() watch1 = Watcher(watch_file, custom_action) # also call custom action function watch1.watch() # start the watch going watch1.look()
def setUp(self) -> None: self.mock_api_helper: TwitterApiHandler = MagicMock() self.mock_os_timer: OsTimer = MagicMock() self.watcher = Watcher(self.mock_api_helper, self.mock_os_timer)
class TestWatcher(TestCase): def setUp(self) -> None: self.mock_api_helper: TwitterApiHandler = MagicMock() self.mock_os_timer: OsTimer = MagicMock() self.watcher = Watcher(self.mock_api_helper, self.mock_os_timer) def test_create_text(self): expected_day = "1 day left. #python #python2" result = self.watcher.create_text(1, 'day') self.assertEqual(expected_day, result) def test_is_this_tweet_sent_2(self): self.mock_api_helper.get_user_timeline = Mock(return_value=FAKE_USER_TIMELINE) tweet = "tweet_2 2. #" result = self.watcher.is_this_tweet_sent(tweet) self.assertEqual(True, result) def test_is_this_tweet_sent_3(self): self.mock_api_helper.get_user_timeline = Mock(return_value=FAKE_USER_TIMELINE) tweet = "tweet_3 1. #" result = self.watcher.is_this_tweet_sent(tweet) self.assertEqual(False, result) def test_post_left_units_tweet(self): self.mock_api_helper.post_tweet = MagicMock() self.watcher.post_left_units_tweet(1, "day", "days") assert self.mock_api_helper.post_tweet.called call_args, call_kwargs = self.mock_api_helper.post_tweet.call_args self.assertEqual("1 day left. #python #python2", call_args[0]) def test_post_left_units_tweet_2(self): self.mock_api_helper.post_tweet = MagicMock() self.watcher.post_left_units_tweet(2, "day", "days") assert self.mock_api_helper.post_tweet.called call_args, call_kwargs = self.mock_api_helper.post_tweet.call_args self.assertEqual("2 days left. #python #python2", call_args[0]) def test_post_watch_ended_tweet(self): self.mock_api_helper.post_tweet = MagicMock() self.watcher.post_watch_ended_tweet() assert self.mock_api_helper.post_tweet.called call_args, call_kwargs = self.mock_api_helper.post_tweet.call_args self.assertEqual(WATCH_END_TEXT, call_args[0]) def test_start_watch_days_left(self): today = 1564053631 # 25.07.2019 self.watcher.post_left_units_tweet = MagicMock() self.watcher.start_the_watch(today) assert self.watcher.post_left_units_tweet.called call_args, call_kwargs = self.watcher.post_left_units_tweet.call_args self.assertEqual(159, call_args[0]) def test_start_watch_days_left_is_repeating_days_true(self): today = 1564053631 # 25.07.2019 mock_crontab = Mock() mock_crontab.schedule = Mock() mock_crontab.schedule.get_next = Mock(return_value="Next Schedule") self.mock_os_timer.is_repeating_day_scheduled = Mock(return_value=mock_crontab) self.watcher.start_the_watch(today) assert not self.mock_os_timer.schedule_repeating_day.called def test_start_watch_days_left_is_repeating_days_false(self): today = 1564053631 # 25.07.2019 self.mock_os_timer.is_repeating_day_scheduled = Mock(return_value=None) self.watcher.start_the_watch(today) assert self.mock_os_timer.schedule_repeating_day.called def test_start_watch_less_days_left(self): today = 1577710800 # 30.12.2019 13:00:00 self.mock_os_timer.is_repeating_day_scheduled = Mock(return_value=CronTab()) self.mock_os_timer.is_repeating_hour_scheduled = Mock(return_value=None) self.watcher.start_the_watch(today) assert self.mock_os_timer.cancel_repeating_day.called assert self.mock_os_timer.schedule_repeating_hour.called def test_start_watch_hours_left(self): today = 1577831400 # 31.12.2019, 22:30 self.watcher.post_left_units_tweet = MagicMock() self.watcher.start_the_watch(today) assert self.watcher.post_left_units_tweet.called call_args, call_kwargs = self.watcher.post_left_units_tweet.call_args self.assertEqual(1, call_args[0]) def test_start_watch_hours_left_timer(self): today = 1577822400 # 31.12.2019, 20:00 self.mock_os_timer.is_repeating_hour_scheduled = Mock(return_value=None) self.watcher.start_the_watch(today) assert self.mock_os_timer.schedule_repeating_hour.called def test_start_watch_hours_left_timer_less(self): today = 1577831400 # 31.12.2019, 22:30 self.mock_os_timer.is_repeating_hour_scheduled = Mock(return_value=CronTab()) self.mock_os_timer.is_repeating_minute_scheduled = Mock(return_value=None) self.watcher.start_the_watch(today) assert self.mock_os_timer.cancel_repeating_hour.called assert self.mock_os_timer.schedule_repeating_minute.called def test_start_watch_mins_left(self): today = 1577835000 # 31.12.2019, 23:30 self.watcher.post_left_units_tweet = MagicMock() self.watcher.start_the_watch(today) assert self.watcher.post_left_units_tweet.called call_args, call_kwargs = self.watcher.post_left_units_tweet.call_args self.assertEqual(30, call_args[0]) def test_start_watch_mins_left_timer(self): today = 1577835000 # 31.12.2019, 23:30 self.mock_os_timer.is_repeating_minute_scheduled = Mock(return_value=None) self.watcher.start_the_watch(today) assert self.mock_os_timer.schedule_repeating_minute.called def test_start_watch_past_deadline(self): today = WATCH_END_EPOCH_SEC + 1 self.watcher.end_the_watch = MagicMock() self.watcher.start_the_watch(today) assert self.watcher.end_the_watch.called def test_start_watch_mins_left_timer_less(self): today = 1577836770 # 31.12.2019, 23:59:30 self.mock_api_helper.get_user_timeline = Mock(return_value=[]) self.watcher.post_watch_ended_tweet = MagicMock() self.watcher.end_the_watch = MagicMock() self.watcher.start_the_watch(today) assert self.watcher.post_watch_ended_tweet.called assert self.watcher.end_the_watch.called def test_start_watch_ended(self): today = 1577836770 # 31.12.2019, 23:59:30 self.watcher.post_watch_ended_tweet = MagicMock() self.watcher.is_this_tweet_sent = Mock(return_value=False) self.watcher.start_the_watch(today) assert self.watcher.post_watch_ended_tweet.called def test_start_watch_ended_already(self): today = 1577836770 # 31.12.2019, 23:59:30 self.watcher.end_the_watch = MagicMock() self.watcher.is_this_tweet_sent = Mock(return_value=True) self.watcher.start_the_watch(today) assert self.watcher.end_the_watch.called
def main(): args = parse() settings = load_settings(args.settings) w = Watcher(settings) w.watch()