Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ pyproject update ✅ Unit Test #308

Merged
merged 14 commits into from
Oct 10, 2023
13 changes: 9 additions & 4 deletions .github/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.291
rev: v0.0.292
hooks:
- id: ruff
#args: [--fix, --exit-non-zero-on-fix]
args: [--fix, --exit-non-zero-on-fix]

- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-merge-conflict
- id: check-toml
- id: check-yaml
- id: trailing-whitespace

- repo: https://github.com/PyCQA/bandit
rev: '1.7.5'
hooks:
- id: bandit
args: ["-c", "pyproject.toml"]
10 changes: 5 additions & 5 deletions findmyorder/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
# Load the default settings file
settings_files=[
os.path.join(ROOT, "default_settings.toml"),
'talky_settings.toml',
'settings.toml',
'.secrets.toml'
".op.toml",
"talky_settings.toml",
"settings.toml",
".secrets.toml" ".op.toml",
],
# Load the.env file
load_dotenv=True,
# Set the environments to True
environments=True,
# Set the default environment
default_env="default",)
default_env="default",
)
2 changes: 1 addition & 1 deletion findmyorder/default_settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ mapping = [

# Instrument to be ignored
# when generating an order
ignore_instrument = "US500 USTEC DOGE"
ignore_instrument = "US500 DOGE"

########################################
### END OF DEFAULT SETTINGS ###
Expand Down
31 changes: 18 additions & 13 deletions findmyorder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ class FindMyOrder:
def __init__(
self,
):
self.logger = logger
"""
Initializes the class instance.

async def search(
self,
my_string: str,
) -> bool:
Args:
self (ClassName): The class instance.

Returns:
None
"""

async def search(self, my_string: str) -> bool:
"""
Search an order.

Expand All @@ -61,7 +66,7 @@ async def search(
"""
if my_string:
string_check = my_string.split()[0].lower()
self.logger.debug("Searching order identifier in {}", string_check)
logger.debug("Searching order identifier in {}", string_check)
if string_check in settings.action_identifier.lower():
return True
return False
Expand Down Expand Up @@ -131,11 +136,11 @@ async def identify_order(
)

order = order_grammar.parse_string(instring=my_string, parse_all=False)
self.logger.debug("Order parsed {}", order)
logger.debug("Order parsed {}", order)
return order.asDict()

except Exception as error:
self.logger.error(error)
logger.error(error)
return error

async def get_order(
Expand All @@ -154,18 +159,18 @@ async def get_order(

"""
if not await self.search(msg):
self.logger.debug("No order identified")
logger.debug("No order identified")
return None
order = await self.identify_order(msg)
if isinstance(order, dict):
order["timestamp"] = datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
if settings.instrument_mapping:
self.logger.debug("mapping")
logger.debug("mapping")
await self.replace_instrument(order)
if order["instrument"] in settings.ignore_instrument:
self.logger.debug("Ignoring instrument {}", order["instrument"])
logger.debug("Ignoring instrument {}", order["instrument"])
return
self.logger.debug("Order identified {}", order)
logger.debug("Order identified {}", order)
return order

async def replace_instrument(self, order):
Expand All @@ -184,5 +189,5 @@ async def replace_instrument(self, order):
if item["id"] == instrument:
order["instrument"] = item["alt"]
break
self.logger.debug("Instrument symbol changed", order)
logger.debug("Instrument symbol changed", order)
return order
15 changes: 10 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ pyparsing = "^3.0.9"


[tool.poetry.group.dev.dependencies]
python-semantic-release = "^8.0.7"
ruff = "*"
python-semantic-release = ">=8.0.8"
ruff = "^0.0.292"
black = "^23.3.0"
pre-commit = "^3.3.1"

[tool.ruff]
select = [
Expand All @@ -43,8 +45,7 @@ exclude = [
".github/*",
"docs/*",
]
ignore = ["E401","F401","F811"]
format = "github"

fixable = ["ALL"]

[tool.pylint.exceptions]
Expand All @@ -64,7 +65,7 @@ pytest = "^7.0"
pytest-cov = "^4.1"
pytest-asyncio = "^0.21.0"
pytest-mock = "^3.11.1"
pytest-loguru = "^0.2.0"
pytest-loguru = "^0.3.0"



Expand Down Expand Up @@ -97,6 +98,10 @@ omit = [
"*/config.py"
]

[tool.bandit]
exclude_dirs = ["tests","docs"]
skips = ["B101","B104"]

[tool.semantic_release]
upload_to_vcs_release = true
version_variables = ["findmyorder/__init__.py:__version__"]
Expand Down
31 changes: 31 additions & 0 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@
return "Buy EURUSD"


@pytest.fixture
def order_2():
"""return order 2"""
return """
📊 FUTURES Exchanges: Binance, ByBit USDT

#AAVEUSDT

🟢LONG ENTRY :- 65.20 - 63.70

Leverage: Cross (2X)

👇TAKE PROFIT

1) 65.70
2) 66.20
3) 66.70

Stop Loss : - 62.00
"""


@pytest.fixture
def result_order():
"""return standard expected results"""
Expand Down Expand Up @@ -217,3 +239,12 @@
assert settings.instrument_mapping is True
assert result["instrument"] == result_crypto_order["instrument"]
assert type(result["timestamp"] is datetime)


@pytest.mark.asyncio
async def test_identify_order2(fmo, order_2):
"""Identify Testing"""
result = await fmo.identify_order(order_2)
assert result is not None
Fixed Show fixed Hide fixed
Fixed Show fixed Hide fixed

Check notice

Code scanning / Bandit

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test

Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
# result = await fmo.get_order(order_2)
# assert result["action"] == "LONG"