Skip to content

Commit

Permalink
add minimal tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume De Saint Martin committed Feb 22, 2020
1 parent bc0d087 commit 0a249b4
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 6 deletions.
15 changes: 9 additions & 6 deletions octobot_backtesting/api/data_file_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,18 @@
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
from os.path import isfile

from octobot_backtesting.converters.data_converter import DataConverter
from octobot_commons.tentacles_management.advanced_manager import get_all_classes_from_parent


async def convert_data_file(data_file_path) -> str:
converter_classes = get_all_classes_from_parent(DataConverter)
for converter_class in converter_classes:
converter = converter_class(data_file_path)
if await converter.can_convert():
if await converter.convert():
return converter.converted_file
if data_file_path and isfile(data_file_path):
converter_classes = get_all_classes_from_parent(DataConverter)
for converter_class in converter_classes:
converter = converter_class(data_file_path)
if await converter.can_convert():
if await converter.convert():
return converter.converted_file
return None
15 changes: 15 additions & 0 deletions tests/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Drakkar-Software OctoBot-Backtesting
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
65 changes: 65 additions & 0 deletions tests/api/test_backtesting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Drakkar-Software OctoBot-Backtesting
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
from octobot_backtesting.api.backtesting import create_independent_backtesting, is_backtesting_enabled, \
get_backtesting_data_files


def _get_default_config():
return {
"crypto-currencies": {
"Bitcoin": {
"pairs": [
"BTC/USD"
]
}
},
"trader-simulator": {
"enabled": True,
"fees": {
"maker": 0.07,
"taker": 0.07
},
"starting-portfolio": {
"BTC": 0.5,
"USDT": 5000
}
},
"trading": {
"reference-market": "BTC",
"risk": 1
}
}


def test_create_independent_backtesting():
try:
create_independent_backtesting(_get_default_config(), [])
except ModuleNotFoundError:
pass


def test_is_backtesting_enabled():
assert is_backtesting_enabled({}) is False
assert is_backtesting_enabled({"backtesting": {}}) is False
assert is_backtesting_enabled({"backtesting": {"enabled": False}}) is False
assert is_backtesting_enabled({"backtesting": {"enabled": True}}) is True


def test_get_backtesting_data_files():
assert get_backtesting_data_files({}) == []
assert get_backtesting_data_files({"backtesting": {}}) == []
assert get_backtesting_data_files({"backtesting": {"files": []}}) == []
assert get_backtesting_data_files({"backtesting": {"files": ["t", "1"]}}) == ["t", "1"]
20 changes: 20 additions & 0 deletions tests/api/test_data_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Drakkar-Software OctoBot-Backtesting
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
from octobot_backtesting.api.data_file import get_all_available_data_files


def test_get_all_available_data_files():
assert get_all_available_data_files() == []
22 changes: 22 additions & 0 deletions tests/api/test_data_file_converters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Drakkar-Software OctoBot-Backtesting
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
import pytest
from octobot_backtesting.api.data_file_converters import convert_data_file


@pytest.mark.asyncio
async def test_convert_data_file_without_converter():
assert await convert_data_file(None) is None
20 changes: 20 additions & 0 deletions tests/api/test_exchange_data_collector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Drakkar-Software OctoBot-Backtesting
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
from octobot_backtesting.api.exchange_data_collector import collect_exchange_historical_data


def test_import():
assert collect_exchange_historical_data is not None
20 changes: 20 additions & 0 deletions tests/api/test_importer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Drakkar-Software OctoBot-Backtesting
# Copyright (c) Drakkar-Software, All rights reserved.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.
from octobot_backtesting.api.importer import get_data_timestamp_interval


def test_import():
assert get_data_timestamp_interval is not None

0 comments on commit 0a249b4

Please sign in to comment.