Exemplo n.º 1
0
def test_create_csv_file(data_object: Data, descending, army_time, start_date,
                         expected_file_to_match):
    """
    Test create CSV file functionality.
    :param data_object: Data object to leverage to test this function.
    :param descending: Boolean that decides whether values in CSV are in descending format or not.
    :param army_time: Boolean that dictates whether dates will be written in army-time format or not.
    :param start_date: Date to have CSV data from.
    """
    remove_test_data()
    data_object.create_table()

    insert_test_data_to_database()
    data_object.data = data_object.get_data_from_database()

    start_date = parser.parse(start_date).date()

    path = data_object.create_csv_file(descending=descending,
                                       army_time=army_time,
                                       start_date=start_date)
    path_to_equal = os.path.join(ROOT_DIR, 'tests', 'data',
                                 'test_create_csv_file_data',
                                 expected_file_to_match)

    assert filecmp.cmp(path, path_to_equal)
Exemplo n.º 2
0
class DownloadThread(QRunnable):
    """
    Thread to use for downloads.
    """
    def __init__(self,
                 interval,
                 symbol,
                 descending=None,
                 armyTime=None,
                 startDate=None,
                 caller=None,
                 logger=None):
        super(DownloadThread, self).__init__()
        self.caller = caller
        self.signals = DownloadSignals()
        self.symbol = symbol
        self.interval = interval
        self.descending = descending
        self.armyTime = armyTime
        self.startDate = startDate
        self.logger = logger
        self.client: Data or None = None

    @pyqtSlot()
    def run(self):
        """
        Initialise the runner function with passed args, kwargs.
        """
        self.signals.started.emit()
        try:
            self.client = Data(interval=self.interval,
                               symbol=self.symbol,
                               update=False)
            data = self.client.custom_get_new_data(
                progress_callback=self.signals.progress,
                locked=self.signals.locked,
                caller=self.caller)
            if data:
                if self.descending is None and self.armyTime is None:
                    self.signals.finished.emit(data, self.caller)
                else:  # This means the CSV generator called this thread.
                    self.signals.progress.emit(100, "Creating CSV file...", '')
                    savedPath = self.client.create_csv_file(
                        descending=self.descending,
                        army_time=self.armyTime,
                        start_date=self.startDate)
                    self.signals.csv_finished.emit(savedPath)
        except Exception as e:
            algobot.MAIN_LOGGER.exception(repr(e))
            self.signals.error.emit(str(e), self.caller)
        finally:
            self.signals.restore.emit(self.caller)

    def stop(self):
        """
        Stop the download loop if it's running.
        """
        if self.client is not None:
            self.client.download_loop = False
Exemplo n.º 3
0
class DownloadThread(QRunnable):
    def __init__(self,
                 interval,
                 symbol,
                 descending=None,
                 armyTime=None,
                 startDate=None):
        super(DownloadThread, self).__init__()
        self.signals = DownloadSignals()
        self.symbol = symbol
        self.interval = interval
        self.descending = descending
        self.armyTime = armyTime
        self.startDate = startDate
        self.client: Data or None = None

    @pyqtSlot()
    def run(self):
        """
        Initialise the runner function with passed args, kwargs.
        """
        self.signals.started.emit()
        try:
            self.client = Data(interval=self.interval,
                               symbol=self.symbol,
                               updateData=False)
            data = self.client.custom_get_new_data(
                progress_callback=self.signals.progress,
                locked=self.signals.locked)
            if data:
                if self.descending is None and self.armyTime is None:
                    self.signals.finished.emit(data)
                else:  # This means the CSV generator called this thread.
                    self.signals.progress.emit(100, "Creating CSV file...", -1)
                    savedPath = self.client.create_csv_file(
                        descending=self.descending,
                        armyTime=self.armyTime,
                        startDate=self.startDate)
                    self.signals.csv_finished.emit(savedPath)
        except Exception as e:
            print(f'Error: {e}')
            traceback.print_exc()
            self.signals.error.emit(str(e))
        finally:
            self.signals.restore.emit()

    def stop(self):
        """
        Stop the download loop if it's running.
        """
        if self.client is not None:
            self.client.downloadLoop = False