Ejemplo n.º 1
0
 def test_time_str01(self):
     """Converting a DateTimeType to string and back again should
        result in the same time.
        Update: actually, as we round the time to seconds on conversion,
        they will *NOT* be the same.
     """
     nn1 = timelib.utc_nowtime()
     #
     tzinfo = pytz.timezone('Europe/Amsterdam')
     timelib.set_local_timezone(tzinfo)
     nn2 = timelib.loc_nowtime()
     for nn in [nn1, nn2]:
         self.convert_test(nn)
Ejemplo n.º 2
0
    def test_loc03(self):
        """timelib.loc_nowtime() must return a timelib.DateTimeType instance
        if a valid timezone was previously set by timelib.set_local_timezone.
        timelib.loc_nowtime_as_string() must return a string.
        """
        tzinfo = pytz.timezone('Europe/Amsterdam')
        timelib.set_local_timezone(tzinfo)
        nn = timelib.loc_nowtime()
        assert isinstance(nn, timelib.DateTimeType), "wrong type returned"

        s = timelib.loc_nowtime_as_string()
        assert s is not None, 'got None'
        assert isinstance(s, str), "string expected"
        print("goo time: {}".format(s))
Ejemplo n.º 3
0
    def __init__(self,
                 qaisession: typing.Optional[qai_helper.QAISession],
                 tz_name: str) -> None:
        """
        This database is accessed by the stocky web server.
        It is passed a :class:`qai_helper.QAISession` instance which it
        uses to access the QAI database via an HTTP API.
        This stock information is stored to a local file locQAIfname as an sqlite3 database
        in the server state directory if a name is provided. Otherwise it is stored in memory.

        Args:
           qaisession: the session instance used to access the QAI server.
           tz_name: the name of the local timezone.
        """
        self.qaisession = qaisession
        timelib.set_local_timezone(tz_name)
        self._current_date = timelib.loc_nowtime().date()
        self._db_has_changed = True
        self._cachedct: typing.Optional[dict] = None
Ejemplo n.º 4
0
    def __init__(self, logger: logging.Logger, cfgname: str) -> None:
        """

        Args:
           logger: a logging instance
           cfgname: the name of the server configuration file (a YAML file)

        This class pull all of the data streams together and passes data
        between the actors. When first instantiated, this class performs
        the following.
          - a configuration file is read in
          - a message queue is instantiated
          - a connection to the RFID reader \
            (via a commlink instance passed to a TLSReader) is established.
          - a way of calling to the QAI API is established.
          - a local database of chemical stocks is opened.

        """
        print("Begin CommonStockyServer")
        super().__init__(logger, "Johnny")
        self.logger.info(
            "serverclass: reading config file '{}'".format(cfgname))
        try:
            self.cfg_dct = serverconfig.read_server_config(cfgname)
        except RuntimeError as err:
            self.logger.error(
                "Error reading server config file: {}".format(err))
            raise
        self.cfg_dct['logger'] = self.logger
        self.logger.debug("serverclass: config file read...{}".format(
            self.cfg_dct))
        timelib.set_local_timezone(self.cfg_dct['TZINFO'])

        # create a timer tick for use in radar mode
        self.logger.info("Instantiating Tickgenerator")
        self.timer_tm = Taskmeister.TickGenerator(self.msgQ, self.logger, 1,
                                                  'radartick')
        self.timer_tm.set_active(False)
        self.logger.info("End of serverclass.__init__")

        self.comm_link: typing.Optional[commlink.BaseCommLink] = None
        self.tls: typing.Optional[TLSAscii.TLSReader] = None
        print("Begin CommonStockyServer")
Ejemplo n.º 5
0
 def setup_method(self) -> None:
     self.utctime = timelib.utc_nowtime()
     ams = pytz.timezone('Europe/Amsterdam')
     timelib.set_local_timezone(ams)
     self.loctime = timelib.loc_nowtime()
Ejemplo n.º 6
0
 def test_loc02a(self):
     """timelib.set_local_timezone must raise a RuntimeError if passed an integer"""
     with pytest.raises(TypeError):
         timelib.set_local_timezone(10)
Ejemplo n.º 7
0
 def test_loc02(self):
     """timelib.set_local_timezone must raise a RuntimeError if passed an
     illegal string."""
     with pytest.raises(RuntimeError):
         timelib.set_local_timezone("now")