# Path: bot/duel_links_runtime.py
# class DuelLinkRunTimeOptions(object):
#     """Class defines options used at runtime"""
#     _active = False
# 
#     @property
#     def active(self):
#         return self._active
# 
#     @active.setter
#     def active(self, value):
#         self._active = True
# 
#     _last_run_at = datetime.datetime.fromtimestamp(default_timestamp)
# 
#     @property
#     def last_run_at(self):
#         return self._last_run_at
# 
#     @last_run_at.setter
#     def last_run_at(self, value):
#         if not isinstance(value, datetime.datetime):
#             self.runtime_error_options("last_run_at", datetime.datetime, type(value))
#             return
#         if self._last_run_at == value:
#             return
#         self._last_run_at = value
#         frame = inspect.currentframe()
#         logger.debug("Value {} modified to {}".format(inspect.getframeinfo(frame).function, value))
#         self.timeout_dump()
# 
#     _next_run_at = datetime.datetime.fromtimestamp(default_timestamp)
# 
#     @property
#     def next_run_at(self):
#         return self._next_run_at
# 
#     @next_run_at.setter
#     def next_run_at(self, value):
#         if not isinstance(value, datetime.datetime):
#             self.runtime_error_options("next_run_at", datetime.datetime, type(value))
#             return
#         if self._next_run_at == value:
#             return
#         self._next_run_at = value
#         frame = inspect.currentframe()
#         logger.debug("Value {} modified to {}".format(inspect.getframeinfo(frame).function, value))
#         self.timeout_dump()
#         self.handle_option_change('next_run_at')
# 
#     _run_now = False
# 
#     @property
#     def run_now(self):
#         return self._run_now
# 
#     @run_now.setter
#     def run_now(self, value):
#         if not isinstance(value, bool):
#             self.runtime_error_options("run_now", bool, type(value))
#             return
#         if self._run_now == value:
#             return
#         self._run_now = value
#         frame = inspect.currentframe()
#         logger.debug("Value {} modified".format(inspect.getframeinfo(frame).function))
#         self.timeout_dump()
#         self.handle_option_change('run_now')
# 
#     _stop = threading.Event()
# 
#     @property
#     def stop(self):
#         return self._stop.is_set()
# 
#     @stop.setter
#     def stop(self, stop):
#         if not isinstance(stop, bool):
#             self.runtime_error_options("stop", bool, type(stop))
#             return
#         if self._stop == stop:
#             return
#         if stop:
#             self._stop.set()
#         else:
#             self._stop.clear()
#         frame = inspect.currentframe()
#         logger.debug("Value {} modified".format(inspect.getframeinfo(frame).function))
#         self.timeout_dump()
#         self.handle_option_change('stop')
# 
#     _playmode = "autoplay"
#     _available_modes = ['autoplay', 'guided']
# 
#     @property
#     def playmode(self):
#         return self._playmode
# 
#     @playmode.setter
#     def playmode(self, playmode):
#         if not isinstance(playmode, str):
#             self.runtime_error_options("playmode", str, type(playmode))
#             return
#         if playmode not in self._available_modes:
#             return
#         if self._playmode == playmode:
#             return
#         self._playmode = playmode
#         frame = inspect.currentframe()
#         logger.debug("Value {} modified".format(inspect.getframeinfo(frame).function))
#         self.timeout_dump()
#         self.handle_option_change('playmode')
# 
#     _battle_calls = {
#         "beforeStart": [],
#         "afterStart" : [],
#         "beforeEnd"  : [],
#         "afterEnd"   : []
#     }
# 
#     @property
#     def battle_calls(self):
#         return self._battle_calls
# 
#     @battle_calls.setter
#     def battle_calls(self, value):
#         if not isinstance(value, dict):
#             self.runtime_error_options("battle_calls", dict, type(value))
#             return
#         if self._battle_calls == value:
#             return
#         self._battle_calls = value
#         frame = inspect.currentframe()
#         logger.debug("Value {} modified".format(inspect.getframeinfo(frame).function))
#         self.timeout_dump()
#         self.handle_option_change('battle_calls')
# 
#     @abstractmethod
#     def runtime_error_options(self, option, expecting_type, got_type):
#         raise NotImplementedError("runtime_error_options not implemented")
# 
#     @abstractmethod
#     def timeout_dump(self):
#         raise NotImplementedError("timeout_dump not implemented")
# 
#     @abstractmethod
#     def handle_option_change(self, value):
#         raise NotImplementedError("handle_option_change not implemented")
# 
# Path: bot/utils/data.py
# def read_json_file(file=data_file):
#     try:
#         with open(file) as f:
#             data = json.load(f, object_hook=date_hook)
#             return data
#     except FileNotFoundError:
#         return None
# 
# def write_data_file(data, file=data_file):
#     with open(file, 'w') as f:
#         json.dump(data, f, sort_keys=True,
#                   indent=4, separators=(',', ': '), default=datetime_handler)


from unittest import TestCase
from bot.duel_links_runtime import DuelLinkRunTimeOptions
from bot.utils.data import read_json_file, write_data_file



class TestDuelLinkRunTimeOptions(TestCase):
    def setUp(self):
        file = r'D:\Sync\OneDrive\Yu-gi-oh_bot\run_at_test.json'
        self.runtimeoptions = DuelLinkRunTimeOptions(file)


    def test_update(self):
        self.runtimeoptions.update()
        self.runtimeoptions.run_now = True
        self.runtimeoptions.dump()

# Path: bot/duel_links_runtime.py
# class DuelLinkRunTimeOptions(object):
#     """Class defines options used at runtime"""
#     _active = False
# 
#     @property
#     def active(self):
#         return self._active
# 
#     @active.setter
#     def active(self, value):
#         self._active = True
# 
#     _last_run_at = datetime.datetime.fromtimestamp(default_timestamp)
# 
#     @property
#     def last_run_at(self):
#         return self._last_run_at
# 
#     @last_run_at.setter
#     def last_run_at(self, value):
#         if not isinstance(value, datetime.datetime):
#             self.runtime_error_options("last_run_at", datetime.datetime, type(value))
#             return
#         if self._last_run_at == value:
#             return
#         self._last_run_at = value
#         frame = inspect.currentframe()
#         logger.debug("Value {} modified to {}".format(inspect.getframeinfo(frame).function, value))
#         self.timeout_dump()
# 
#     _next_run_at = datetime.datetime.fromtimestamp(default_timestamp)
# 
#     @property
#     def next_run_at(self):
#         return self._next_run_at
# 
#     @next_run_at.setter
#     def next_run_at(self, value):
#         if not isinstance(value, datetime.datetime):
#             self.runtime_error_options("next_run_at", datetime.datetime, type(value))
#             return
#         if self._next_run_at == value:
#             return
#         self._next_run_at = value
#         frame = inspect.currentframe()
#         logger.debug("Value {} modified to {}".format(inspect.getframeinfo(frame).function, value))
#         self.timeout_dump()
#         self.handle_option_change('next_run_at')
# 
#     _run_now = False
# 
#     @property
#     def run_now(self):
#         return self._run_now
# 
#     @run_now.setter
#     def run_now(self, value):
#         if not isinstance(value, bool):
#             self.runtime_error_options("run_now", bool, type(value))
#             return
#         if self._run_now == value:
#             return
#         self._run_now = value
#         frame = inspect.currentframe()
#         logger.debug("Value {} modified".format(inspect.getframeinfo(frame).function))
#         self.timeout_dump()
#         self.handle_option_change('run_now')
# 
#     _stop = threading.Event()
# 
#     @property
#     def stop(self):
#         return self._stop.is_set()
# 
#     @stop.setter
#     def stop(self, stop):
#         if not isinstance(stop, bool):
#             self.runtime_error_options("stop", bool, type(stop))
#             return
#         if self._stop == stop:
#             return
#         if stop:
#             self._stop.set()
#         else:
#             self._stop.clear()
#         frame = inspect.currentframe()
#         logger.debug("Value {} modified".format(inspect.getframeinfo(frame).function))
#         self.timeout_dump()
#         self.handle_option_change('stop')
# 
#     _playmode = "autoplay"
#     _available_modes = ['autoplay', 'guided']
# 
#     @property
#     def playmode(self):
#         return self._playmode
# 
#     @playmode.setter
#     def playmode(self, playmode):
#         if not isinstance(playmode, str):
#             self.runtime_error_options("playmode", str, type(playmode))
#             return
#         if playmode not in self._available_modes:
#             return
#         if self._playmode == playmode:
#             return
#         self._playmode = playmode
#         frame = inspect.currentframe()
#         logger.debug("Value {} modified".format(inspect.getframeinfo(frame).function))
#         self.timeout_dump()
#         self.handle_option_change('playmode')
# 
#     _battle_calls = {
#         "beforeStart": [],
#         "afterStart" : [],
#         "beforeEnd"  : [],
#         "afterEnd"   : []
#     }
# 
#     @property
#     def battle_calls(self):
#         return self._battle_calls
# 
#     @battle_calls.setter
#     def battle_calls(self, value):
#         if not isinstance(value, dict):
#             self.runtime_error_options("battle_calls", dict, type(value))
#             return
#         if self._battle_calls == value:
#             return
#         self._battle_calls = value
#         frame = inspect.currentframe()
#         logger.debug("Value {} modified".format(inspect.getframeinfo(frame).function))
#         self.timeout_dump()
#         self.handle_option_change('battle_calls')
# 
#     @abstractmethod
#     def runtime_error_options(self, option, expecting_type, got_type):
#         raise NotImplementedError("runtime_error_options not implemented")
# 
#     @abstractmethod
#     def timeout_dump(self):
#         raise NotImplementedError("timeout_dump not implemented")
# 
#     @abstractmethod
#     def handle_option_change(self, value):
#         raise NotImplementedError("handle_option_change not implemented")
# 
# Path: bot/utils/data.py
# def read_json_file(file=data_file):
#     try:
#         with open(file) as f:
#             data = json.load(f, object_hook=date_hook)
#             return data
#     except FileNotFoundError:
#         return None
# 
# def write_data_file(data, file=data_file):
#     with open(file, 'w') as f:
#         json.dump(data, f, sort_keys=True,
#                   indent=4, separators=(',', ': '), default=datetime_handler)


# Path: bot/test_duelLinkRunTimeOptions.py
from unittest import TestCase
from bot.duel_links_runtime import DuelLinkRunTimeOptions
from bot.utils.data import read_json_file, write_data_file




class TestDuelLinkRunTimeOptions(TestCase):
    def setUp(self):
        file = r'D:\Sync\OneDrive\Yu-gi-oh_bot\run_at_test.json'
        self.runtimeoptions = DuelLinkRunTimeOptions(file)


    def test_update(self):
        self.runtimeoptions.update()
        self.runtimeoptions.run_now = True
        self.runtimeoptions.dump()

        tmp_data = read_json_file(self.runtimeoptions._file)