Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Compatibility with latest WEI (v0.5.6); update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LuckierDodge committed Mar 22, 2024
1 parent a9d5ddc commit bfab899
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
1 change: 0 additions & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ services:
image: ${IMAGE}
build:
context: .
dockerfile: ${DOCKERFILE}
tags:
- ${IMAGE}:latest
- ${IMAGE}:dev
Expand Down
23 changes: 23 additions & 0 deletions tests/test_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""Base module tests."""

import unittest


class TestModule_Base(unittest.TestCase):
"""Base test class for this module."""

pass


class TestImports(TestModule_Base):
"""Test the imports of the module are working correctly"""

def test_driver_import(self):
"""Test the driver and rest node imports"""
import sleep_rest_node

assert sleep_rest_node


if __name__ == "__main__":
unittest.main()
27 changes: 15 additions & 12 deletions tests/test_module.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""Tests the basic functionality of the Sleep Module."""
"""Tests the basic functionality of the Module."""

import time
import unittest
from pathlib import Path

import requests
from wei import ExperimentClient
from wei.core.data_classes import ModuleAbout, WorkcellData, WorkflowStatus
from wei.core.data_classes import ModuleAbout, Workcell, WorkflowStatus


class TestWEI_Base(unittest.TestCase):
Expand All @@ -19,9 +19,14 @@ def __init__(self, *args, **kwargs):
self.workcell_file = self.root_dir / Path(
"tests/workcell_defs/test_workcell.yaml"
)
self.workcell = WorkcellData.from_yaml(self.workcell_file)
self.workcell = Workcell.from_yaml(self.workcell_file)
self.server_host = self.workcell.config.server_host
self.server_port = self.workcell.config.server_port
self.experiment = ExperimentClient(
self.server_host,
self.server_port,
"TestExperiment",
)
self.url = f"http://{self.server_host}:{self.server_port}"
self.module_url = "http://sleep_module:2000"
self.redis_host = self.workcell.config.redis_host
Expand All @@ -30,7 +35,7 @@ def __init__(self, *args, **kwargs):
start_time = time.time()
while True:
try:
if requests.get(self.url + "/wc/state").status_code == 200:
if requests.get(self.url + "/wc/state").ok:
break
except Exception:
pass
Expand All @@ -39,7 +44,7 @@ def __init__(self, *args, **kwargs):
raise TimeoutError("Server did not start in 60 seconds")
while True:
try:
if requests.get(self.module_url + "/state").status_code == 200:
if requests.get(self.module_url + "/state").ok:
break
except Exception:
pass
Expand All @@ -48,25 +53,23 @@ def __init__(self, *args, **kwargs):
raise TimeoutError("Module did not start in 60 seconds")


class TestSleepModule(TestWEI_Base):
"""Tests the basic functionality of the Sleep Module."""
class TestModuleInterfaces(TestWEI_Base):
"""Tests the basic functionality of the Module."""

def test_sleep_action(self):
"""Tests that the sleep action works"""
# Send sleep action
exp = ExperimentClient(self.server_host, self.server_port, "")

start_time = time.time()
result = exp.start_run(
result = self.experiment.start_run(
Path(self.root_dir) / Path("tests/workflow_defs/test_workflow.yaml"),
simulate=False,
blocking=True,
)
assert result["status"] == WorkflowStatus.COMPLETED
assert time.time() - start_time > 5

def test_sleep_about(self):
"""Tests that the sleep /about works"""
def test_module_about(self):
"""Tests that the module's /about endpoint works"""
response = requests.get(self.module_url + "/about")
assert response.status_code == 200
ModuleAbout(**response.json())
Expand Down
10 changes: 0 additions & 10 deletions tests/wei.compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ services:
- PYTHONUNBUFFERED=1 # Fix weird bug with empty logging
volumes:
- ${WORKCELLS_DIR}:/workcell_defs
- ${WEI_DATA_DIR}:/home/app/.wei
- diaspora_config:/home/app/.diaspora
command: python3 -m wei.server --workcell /workcell_defs/${WORKCELL_FILENAME}
depends_on:
- wei_redis
Expand All @@ -23,7 +21,6 @@ services:
container_name: wei_engine
volumes:
- ${WORKCELLS_DIR}:/workcell_defs
- ${WEI_DATA_DIR}:/home/app/.wei
env_file: ../.env
environment:
- PYTHONUNBUFFERED=1 # Fix weird bug with empty logging
Expand All @@ -39,10 +36,3 @@ services:
volumes:
- ${REDIS_DIR}:/data
command: redis-server --save 60 1 --loglevel warning

################
# Data Storage #
################
volumes:
diaspora_config:
driver: local

0 comments on commit bfab899

Please sign in to comment.