Skip to content

Commit

Permalink
AB#417 Some work-in-progress ConsoleSpinner tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Chroxvi committed Oct 6, 2023
1 parent 5847a3e commit 4f21bca
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cotainr/tests/tracing/stubs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"""


import contextlib


class AlwaysCompareFalse:
"""A stub that returns False for all Python "rich comparisons"."""

Expand Down Expand Up @@ -52,3 +55,9 @@ def is_set(self):

def set(self):
self.remaining_spins = 0


@contextlib.contextmanager
def RaiseOnEnterContext():
raise NotImplementedError("Entered context")
yield
86 changes: 86 additions & 0 deletions cotainr/tests/tracing/test_console_spinner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"""
cotainr - a user space Apptainer/Singularity container builder.
Copyright DeiC, deic.dk
Licensed under the European Union Public License (EUPL) 1.2
- see the LICENSE file for details.
"""
import sys

import pytest

from cotainr.tracing import ConsoleSpinner, StreamWriteProxy
from .stubs import RaiseOnEnterContext


class TestConstructor:
def test_attributes(self):
spinner = ConsoleSpinner()
assert isinstance(spinner._stdout_proxy, StreamWriteProxy)
assert spinner._stdout_proxy._stream is sys.stdout
assert isinstance(spinner._stderr_proxy, StreamWriteProxy)
assert spinner._stderr_proxy._stream is sys.stderr
assert spinner._true_input_func is input
assert spinner._spinning_msg is None


class TestContext:
def test_as_atomic_enter(self):
console_spinner = ConsoleSpinner()
console_spinner._as_atomic = RaiseOnEnterContext()
with pytest.raises(NotImplementedError, match=r"^Entered context$"):
console_spinner.__enter__()

def test_as_atomic_exit(self):
console_spinner = ConsoleSpinner()
console_spinner._as_atomic = RaiseOnEnterContext()
with pytest.raises(NotImplementedError, match=r"^Entered context$"):
console_spinner.__exit__(None, None, None)

def test_correctly_handling_input(self):
1 / 0

def test_correctly_spinning_stdout_msg(self):
1 / 0

def test_correctly_spinning_stderr_msg(self):
1 / 0

def test_exiting_context_with_spinning_msg(self):
1 / 0

def test_exiting_context_without_spinnnig_msg(self):
1 / 0

def test_reentering_context(self):
1 / 0


class Test_UpdateSpinnerMsg:
def test_as_atomic(self):
console_spinner = ConsoleSpinner()
console_spinner._as_atomic = RaiseOnEnterContext()
with pytest.raises(NotImplementedError, match=r"^Entered context$"):
console_spinner._update_spinner_msg("", stream=None)

def test_first_message_correctly_started(self):
1 / 0

def test_message_correctly_updated(self):
1 / 0


class Test_ThreadSafeInput:
def test_as_atomic(self):
console_spinner = ConsoleSpinner()
console_spinner._as_atomic = RaiseOnEnterContext()
wrapped_input_func = console_spinner._thread_safe_input(lambda: None)
with pytest.raises(NotImplementedError, match=r"^Entered context$"):
wrapped_input_func()

def test_stop_spinning_msg(self):
1 / 0

def test_wrap_input_func(self):
1 / 0

0 comments on commit 4f21bca

Please sign in to comment.