Skip to content

Commit

Permalink
✅ Unit Test ♻️
Browse files Browse the repository at this point in the history
  • Loading branch information
mraniki committed Jul 5, 2024
1 parent 604c3a1 commit 5b770f3
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
2 changes: 1 addition & 1 deletion findmyorder/default_settings.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

[default]
# Dynaconf settings verification
VALUE = "Production - Default"
# VALUE = "Production - Default"

# Module Enable/Disable
findmyorder_enabled = true
Expand Down
1 change: 1 addition & 0 deletions findmyorder/handler/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def __init__(self, **kwargs):
"""

super().__init__(**kwargs)
self.client = "basic"

async def identify_order(
self,
Expand Down
3 changes: 1 addition & 2 deletions findmyorder/handler/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,9 @@ def __init__(self, **kwargs):
"""
Initialize the chat client.
"""

self.name = kwargs.get("name", None)
self.client = None
self.enabled = kwargs.get("enabled", None)

self.action_identifier = kwargs.get("action_identifier", None)
self.stop_loss_identifier = kwargs.get("stop_loss_identifier", None)
self.take_profit_identifier = kwargs.get("take_profit_identifier", None)
Expand Down
1 change: 1 addition & 0 deletions findmyorder/handler/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def __init__(self, **kwargs):
"""

super().__init__(**kwargs)
self.client = "standard"

async def identify_order(
self,
Expand Down
14 changes: 8 additions & 6 deletions findmyorder/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,28 +47,30 @@ def __init__(
self.enabled = settings.findmyorder_enabled
if not self.enabled:
logger.info("FindMyOrder is disabled. No Parser will be created.")
self.client_classes = self.get_all_client_classes()
self.clients = []
# Create a client for each client in settings.myllm
for name, client_config in settings.findmyorder.items():
logger.debug("client_config: {}", client_config)
# Skip template and empty string client names
if name in ["", "template"] or not client_config.get("enabled"):
continue
try:
# Create the client
logger.debug("Creating client {}", name)
logger.debug("Creating FMO parser {}", name)
client = self._create_client(**client_config, name=name)
# If the client has a valid client attribute, append it to the list
if client and getattr(client, "client", None):
if client and getattr(client, "parser", None):
self.clients.append(client)
except Exception as e:
# Log the error if the client fails to be created
logger.error(f"Failed to create client {name}: {e}")
logger.error(f"Failed to create parser {name}: {e}")

# Log the number of clients that were created
logger.info(f"Loaded {len(self.clients)} clients")
logger.info(f"Loaded {len(self.clients)} parsers")
if not self.clients:
logger.warning(
"No clients were created. Check your settings or disable the module."
"No Parsers were created. Check your settings or disable the module."
)

def _create_client(self, **kwargs):
Expand Down Expand Up @@ -106,7 +108,7 @@ def _create_client(self, **kwargs):
"""
library = kwargs.get("parser_library", "standard")
client_class = self.client_classes.get(f"{library.capitalize()}Handler")

logger.debug(f"Creating {library} client with {kwargs} and {client_class}")
if client_class is None:
logger.error(f"library {library} not supported")
return None
Expand Down
2 changes: 2 additions & 0 deletions tests/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,13 @@ async def test_info(fmo):
print(result)
assert result is not None
assert "FindMyOrder" in result
assert "ℹ️" in result


@pytest.mark.asyncio
async def test_search_valid_order(fmo, crypto_order):
"""Search Testing"""
print(settings)
assert await fmo.search(crypto_order) is True


Expand Down

0 comments on commit 5b770f3

Please sign in to comment.