# Path: dftimewolf/lib/state.py
# T = TypeVar("T", bound="interface.AttributeContainer")  # pylint: disable=invalid-name,line-too-long
# NEW_ISSUE_URL = 'https://github.com/log2timeline/dftimewolf/issues/new'
# class DFTimewolfState(object):
#   def __init__(self, config: Type[Config]) -> None:
#   def _InvokeModulesInThreads(self, callback: Callable[[Any], Any]) -> None:
#   def ImportRecipeModules(self, module_locations: Dict[str, str]) -> None:
#   def LoadRecipe(self,
#                  recipe: Dict[str, Any],
#                  module_locations: Dict[str, str]) -> None:
#   def FormatExecutionPlan(self) -> str:
#   def LogExecutionPlan(self) -> None:
#   def AddToCache(self, name: str, value: Any) -> None:
#   def GetFromCache(self, name: str, default_value: Any=None) -> Any:
#   def StoreContainer(self, container: "interface.AttributeContainer") -> None:
#   def GetContainers(self,
#                     container_class: Type[T],
#                     pop: bool=False) -> Sequence[T]:
#   def DedupeContainers(self, container_class: Type[T]) -> None:
#   def _SetupModuleThread(self, module_definition: Dict[str, str]) -> None:
#   def SetupModules(self) -> None:
#   def _RunModuleThread(self, module_definition: Dict[str, str]) -> None:
#   def RunPreflights(self) -> None:
#   def CleanUpPreflights(self) -> None:
#   def InstantiateModule(self, module_name: str) -> "dftw_module.BaseModule":
#   def RunModules(self) -> None:
#   def RegisterStreamingCallback(
#       self,
#       target: Callable[["interface.AttributeContainer"], Any],
#       container_type: Type["interface.AttributeContainer"]) -> None:
#   def StreamContainer(self, container: "interface.AttributeContainer") -> None:
#   def AddError(self, error: DFTimewolfError) -> None:
#   def CleanUp(self) -> None:
#   def CheckErrors(self, is_global: bool=False) -> None:
# 
# Path: dftimewolf/lib/errors.py
# class DFTimewolfError(Exception):
#   """Class to represent a DFTimewolfError.
# 
#   Attributes:
#     message (str): The error message.
#     name (str): Name of the module that generated the error.
#     stacktrace (Optional[str]): Stacktrace leading to the error.
#     critical (Optional[bool]): Whether the error is critical or not. Critical
#         errors interrupt the recipe execution flow.
#     unexpected (Optional[bool]): Whether the error is unexpected.
#   """
# 
#   def __init__(self,
#                message: Optional[str]=None,
#                name: Optional[str]=None,
#                stacktrace: Optional[str]=None,
#                critical: bool=False,
#                unexpected: bool=False) -> None:
#     """Initializes the DFTimewolfError with provided or default message."""
#     super(DFTimewolfError, self).__init__(message)
#     self.message = message or 'An error occurred.'
#     self.name = name
#     self.stacktrace = stacktrace
#     self.critical = critical
#     self.unexpected = unexpected
# 
# Path: dftimewolf/lib/preflights/sanity_checks.py
# DATE_ORDER_ERROR_STRING = 'Hold fast time traveller, your start date {0:s} is after your end date {1:s}'
# class SanityChecks(module.PreflightModule):
#   def __init__(self,
#                state: DFTimewolfState,
#                name: Optional[str]=None,
#                critical: bool=False) -> None:
#   def SetUp(self,  # pylint: disable=arguments-differ
#             startdate: str,
#             enddate: str,
#             dateformat: str) -> None:
#   def Process(self) -> None:
#   def _AreDatesValid(self) -> None:
#   def CleanUp(self) -> None:
# 
# Path: dftimewolf/config.py
# class Config(object):
#   def GetExtra(cls, name: str='') -> Dict[str, Any]:
#   def LoadExtra(cls, filename: str) -> bool:
#   def LoadExtraData(cls, json_string: bytes) -> None:
#   def ClearExtra(cls) -> None:


import unittest
from dftimewolf.lib import state
from dftimewolf.lib.errors import DFTimewolfError
from dftimewolf.lib.preflights import sanity_checks
from dftimewolf import config


class SanityChecks(unittest.TestCase):
  """Tests for the Sanity Checker preflight."""

  def testInitialization(self):
    """Test initialisation of the sanity checker."""
    test_state = state.DFTimewolfState(config.Config)
    checker = sanity_checks.SanityChecks(test_state)
    self.assertIsNotNone(checker)

  def testInvalidDateOrder(self):
    """Test that dates in the incorrect order produces an error."""
    test_state = state.DFTimewolfState(config.Config)
    checker = sanity_checks.SanityChecks(test_state)

    with self.assertRaises(DFTimewolfError) as cm:
      checker.SetUp(
          startdate='2020-10-31', enddate='2020-10-01', dateformat='%Y-%m-%d')
      checker.Process()

    self.assertEqual(str(cm.exception),
        'Hold fast time traveller, your start date 2020-10-31 is after your end date 2020-10-01',  # pylint: disable=line-too-long
        'Exception differs from expected')

  def testInvalidDateFormat(self):
    """Test that invalid date formats produce an error."""
    test_state = state.DFTimewolfState(config.Config)
    checker = sanity_checks.SanityChecks(test_state)


# Path: dftimewolf/lib/state.py
# T = TypeVar("T", bound="interface.AttributeContainer")  # pylint: disable=invalid-name,line-too-long
# NEW_ISSUE_URL = 'https://github.com/log2timeline/dftimewolf/issues/new'
# class DFTimewolfState(object):
#   def __init__(self, config: Type[Config]) -> None:
#   def _InvokeModulesInThreads(self, callback: Callable[[Any], Any]) -> None:
#   def ImportRecipeModules(self, module_locations: Dict[str, str]) -> None:
#   def LoadRecipe(self,
#                  recipe: Dict[str, Any],
#                  module_locations: Dict[str, str]) -> None:
#   def FormatExecutionPlan(self) -> str:
#   def LogExecutionPlan(self) -> None:
#   def AddToCache(self, name: str, value: Any) -> None:
#   def GetFromCache(self, name: str, default_value: Any=None) -> Any:
#   def StoreContainer(self, container: "interface.AttributeContainer") -> None:
#   def GetContainers(self,
#                     container_class: Type[T],
#                     pop: bool=False) -> Sequence[T]:
#   def DedupeContainers(self, container_class: Type[T]) -> None:
#   def _SetupModuleThread(self, module_definition: Dict[str, str]) -> None:
#   def SetupModules(self) -> None:
#   def _RunModuleThread(self, module_definition: Dict[str, str]) -> None:
#   def RunPreflights(self) -> None:
#   def CleanUpPreflights(self) -> None:
#   def InstantiateModule(self, module_name: str) -> "dftw_module.BaseModule":
#   def RunModules(self) -> None:
#   def RegisterStreamingCallback(
#       self,
#       target: Callable[["interface.AttributeContainer"], Any],
#       container_type: Type["interface.AttributeContainer"]) -> None:
#   def StreamContainer(self, container: "interface.AttributeContainer") -> None:
#   def AddError(self, error: DFTimewolfError) -> None:
#   def CleanUp(self) -> None:
#   def CheckErrors(self, is_global: bool=False) -> None:
# 
# Path: dftimewolf/lib/errors.py
# class DFTimewolfError(Exception):
#   """Class to represent a DFTimewolfError.
# 
#   Attributes:
#     message (str): The error message.
#     name (str): Name of the module that generated the error.
#     stacktrace (Optional[str]): Stacktrace leading to the error.
#     critical (Optional[bool]): Whether the error is critical or not. Critical
#         errors interrupt the recipe execution flow.
#     unexpected (Optional[bool]): Whether the error is unexpected.
#   """
# 
#   def __init__(self,
#                message: Optional[str]=None,
#                name: Optional[str]=None,
#                stacktrace: Optional[str]=None,
#                critical: bool=False,
#                unexpected: bool=False) -> None:
#     """Initializes the DFTimewolfError with provided or default message."""
#     super(DFTimewolfError, self).__init__(message)
#     self.message = message or 'An error occurred.'
#     self.name = name
#     self.stacktrace = stacktrace
#     self.critical = critical
#     self.unexpected = unexpected
# 
# Path: dftimewolf/lib/preflights/sanity_checks.py
# DATE_ORDER_ERROR_STRING = 'Hold fast time traveller, your start date {0:s} is after your end date {1:s}'
# class SanityChecks(module.PreflightModule):
#   def __init__(self,
#                state: DFTimewolfState,
#                name: Optional[str]=None,
#                critical: bool=False) -> None:
#   def SetUp(self,  # pylint: disable=arguments-differ
#             startdate: str,
#             enddate: str,
#             dateformat: str) -> None:
#   def Process(self) -> None:
#   def _AreDatesValid(self) -> None:
#   def CleanUp(self) -> None:
# 
# Path: dftimewolf/config.py
# class Config(object):
#   def GetExtra(cls, name: str='') -> Dict[str, Any]:
#   def LoadExtra(cls, filename: str) -> bool:
#   def LoadExtraData(cls, json_string: bytes) -> None:
#   def ClearExtra(cls) -> None:


# Path: tests/lib/preflights/sanity_checks.py
import unittest
from dftimewolf.lib import state
from dftimewolf.lib.errors import DFTimewolfError
from dftimewolf.lib.preflights import sanity_checks
from dftimewolf import config



class SanityChecks(unittest.TestCase):
  """Tests for the Sanity Checker preflight."""

  def testInitialization(self):
    """Test initialisation of the sanity checker."""
    test_state = state.DFTimewolfState(config.Config)
    checker = sanity_checks.SanityChecks(test_state)
    self.assertIsNotNone(checker)

  def testInvalidDateOrder(self):
    """Test that dates in the incorrect order produces an error."""
    test_state = state.DFTimewolfState(config.Config)
    checker = sanity_checks.SanityChecks(test_state)

    with self.assertRaises(DFTimewolfError) as cm:
      checker.SetUp(
          startdate='2020-10-31', enddate='2020-10-01', dateformat='%Y-%m-%d')
      checker.Process()

    self.assertEqual(str(cm.exception),
        'Hold fast time traveller, your start date 2020-10-31 is after your end date 2020-10-01',  # pylint: disable=line-too-long
        'Exception differs from expected')

  def testInvalidDateFormat(self):
    """Test that invalid date formats produce an error."""
    test_state = state.DFTimewolfState(config.Config)
    checker = sanity_checks.SanityChecks(test_state)


    with self.assertRaises(DFTimewolfError) as cm: