Skip to content

Commit

Permalink
chore: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alberto-abarzua committed Dec 8, 2023
1 parent 390b926 commit b2f5c3d
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion controller/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ WORKDIR /app
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

RUN pip install --no-cache-dir pdm==2.10.3
RUN pip install --no-cache-dir pdm==2.10.4

ENV PYTHONPATH "${PYTHONPATH}:/app/src"

Expand Down
4 changes: 3 additions & 1 deletion controller/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ isort = "isort src"
black = "black src"
pure_lint = "flake8 src"
type_check = "mypy src"
test = "python -m unittest discover -s src/ribot/tests -p 'test_*.py' -v"
test_no_sleep = "python -m unittest discover -s src/ribot/tests -p 'test_*.py' -v"
sleep = "sleep 3"
test = {composite = ["test_no_sleep", "sleep"]}
format = {composite = ["isort", "black"]}
lint = {composite = ["pure_lint", "type_check"]}
main = "python src/ribot/sample_main.py"
Expand Down
4 changes: 4 additions & 0 deletions controller/src/ribot/tests/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def setUpClass(cls) -> None:
@classmethod
def tearDownClass(cls) -> None:
cls.controller.stop()
time.sleep(3)

def tearDown(self) -> None:
self.controller.move_joints_to([0, 0, 0, 0, 0, 0])
Expand Down Expand Up @@ -271,3 +272,6 @@ def test_move_queue_size(self) -> None:
self.controller.stop_movement()
time.sleep(0.5)
self.assertEqual(self.controller.move_queue_size, 0)

if __name__ == "__main__":
unittest.main()
32 changes: 19 additions & 13 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env python3

from logging import captureWarnings
from sys import stdout
import time
import argparse
Expand Down Expand Up @@ -73,7 +74,7 @@ def get_file_list(self, services: List[str]) -> List[str]:
file_list.extend(['-f', self.get_service_from_name(service).full_path])
return file_list

def dc_run(self, service_name: str, command: str, env={}, service_ports_and_aliases=False, exec=False, mute=False):
def dc_run(self, service_name: str, command: str, env={}, service_ports_and_aliases=False, exec=False):
command_list = command.split(' ')
service = self.get_service_from_name(service_name)

Expand All @@ -88,15 +89,11 @@ def dc_run(self, service_name: str, command: str, env={}, service_ports_and_alia

new_command.extend(command_list)

try:
result = subprocess.run(new_command, env={**os.environ, **env}, check=True,
stderr=subprocess.PIPE)
print(result.stderr.decode('utf-8'))
return result.returncode
except subprocess.CalledProcessError as e:
print("Command failed with the following output:")
print(e.output.decode('utf-8')) # Output includes both stdout and stderr
return e.returncode
result = subprocess.run(new_command, env={**os.environ, **env})
# repalce with os.system to get output
# result = os.system(' '.join(new_command))

return result.returncode

def dc_up(self, files: List[str], env: dict = {}, detached=False):

Expand All @@ -123,7 +120,13 @@ def dc_logs(self, files: List[str]):

def dc_command(self, files: List[str], command: str):
file_list = self.get_file_list(files)
command_list = command.split(' ')
command_list = []

if "run" in command:
command_list += ["run", "--service-ports", "--use-aliases"]
command_list += command.split(' ')[1:]
else:
command_list += command.split(' ')
return subprocess.check_call(['docker', 'compose', *file_list] + command_list, env={**os.environ})


Expand Down Expand Up @@ -151,7 +154,10 @@ def source_settings(self, file_path):
settings = toml.load(f)
for field, value_dict in settings.items():
for sub_key, value in value_dict.items():
os.environ[f"{field}_{sub_key}".upper()] = str(value)
if "no_pref" in field.lower():
os.environ[sub_key.upper()] = str(value)
else:
os.environ[f"{field}_{sub_key}".upper()] = str(value)

def source_env(self, file_path):
pattern = re.compile(r'^(?:export\s+)?([\w\.]+)\s*=\s*(.*)$')
Expand Down Expand Up @@ -339,7 +345,7 @@ def build_esp(self, **kwargs):
def run_command(self, args):
container, cmd = args
try:
self.docker_manager.dc_run(container, cmd, mute=True)
self.docker_manager.dc_run(container, cmd, service_ports_and_aliases=True)
except subprocess.CalledProcessError as e:
print(f"Error running command: {e}")

Expand Down

0 comments on commit b2f5c3d

Please sign in to comment.