Skip to content

Commit

Permalink
Added zero and one option
Browse files Browse the repository at this point in the history
  • Loading branch information
tech-chad committed Oct 22, 2021
1 parent 792205b commit 4177102
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pymatrix/pymatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,13 @@ def set_extended_chars(cls, state: str):
cls.extended_char = "only"
cls.char_list = EXT_CHAR_LIST

@classmethod
def set_zero_one(cls, mode: bool):
if mode:
cls.char_list = ["0", "1"]
else:
cls.char_list = CHAR_LIST


def matrix_loop(screen, color_mode: str, args: argparse.Namespace) -> None:
""" Main loop. """
Expand All @@ -174,13 +181,16 @@ def matrix_loop(screen, color_mode: str, args: argparse.Namespace) -> None:
count = cycle = 0 # used for cycle through colors mode
cycle_delay = 500
spacer = 2 if double_space else 1
zero_one = args.zero_one

if args.test_mode:
wake_up_time = 20
else:
wake_up_time = randint(2000, 3000)

SingleLine.set_test_mode(args.test_mode, args.test_mode_ext)
if zero_one:
SingleLine.set_zero_one(True)

if color_mode == "multiple" or color_mode == "random":
setup_curses_colors("random")
Expand Down Expand Up @@ -344,8 +354,22 @@ def matrix_loop(screen, color_mode: str, args: argparse.Namespace) -> None:
SingleLine.set_extended_chars("only")
elif SingleLine.extended_char == "only":
SingleLine.set_extended_chars("on")
elif ch == 122 and not zero_one: # z
SingleLine.set_zero_one(True)
line_list.clear()
screen.clear()
screen.refresh()
zero_one = True
elif ch == 90 and zero_one: # Z
SingleLine.set_zero_one(False)
line_list.clear()
screen.clear()
screen.refresh()
zero_one = False

elif ch in [100, 68]: # d, D
SingleLine.set_zero_one(False)
zero_one = False
bold_char = False
bold_all = False
setup_curses_colors("green")
Expand Down Expand Up @@ -465,6 +489,8 @@ def display_commands() -> None:
print("l Toggle double space lines")
print("e Extended characters on and off")
print("E Extended characters only")
print("z 1 and 0 Mode On")
print("Z 1 and 0 Mode Off")
print("r,t,y,u,i,o,p Set color")
print("R,T,Y,U,I,O,P Set lead character color")
print("shift 0 - 9 Cycle color delay (0-Fast, 4-Default, 9-Slow)")
Expand Down Expand Up @@ -503,6 +529,8 @@ def argument_parsing(argv: Optional[Sequence[str]] = None) -> argparse.Namespace
help="use only extended characters (overrides -e)")
parser.add_argument("-l", dest="double_space", action="store_true",
help="Double space lines")
parser.add_argument("-z", dest="zero_one", action="store_true",
help="Show only zero and ones. Binary")
parser.add_argument("--list_colors", action="store_true",
help="Show available colors and exit. ")
parser.add_argument("--list_commands", action="store_true",
Expand Down
8 changes: 8 additions & 0 deletions tests/test_argument_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,14 @@ def test_argument_parsing_wakeup(test_value, expected_result):
assert result.wakeup == expected_result


@pytest.mark.parametrize("test_value, expected_result", [
([], False), (["-z"], True),
])
def test_argument_parsing_zero_one(test_value, expected_result):
result = pymatrix.argument_parsing(test_value)
assert result.zero_one == expected_result


# testing helper functions
@pytest.mark.parametrize("test_values, expected_results", [
("0", 0), ("1", 1), ("2", 2), ("3", 3), ("4", 4),
Expand Down
43 changes: 43 additions & 0 deletions tests/test_pymatrix.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest import mock
import pytest
from hecate import Runner
from time import sleep

from pymatrix import pymatrix

Expand Down Expand Up @@ -230,3 +231,45 @@ def test_pymatrix_double_space(width):
h.await_text("T")
sc = h.screenshot()
assert "Traceback" not in sc


def test_pymatrix_zero_one_command_line():
with Runner(*pymatrix_run("-z", "-l"), width=75, height=50) as h:
h.await_text("0")
h.await_text("1")
sc = h.screenshot()
assert "T" not in sc
assert "5" not in sc


def test_pymatrix_zero_one_running_command():
with Runner(*pymatrix_run("--test_mode", "-l"), width=100, height=50) as h:
h.await_text("T")
h.write("z")
h.press("Enter")
h.await_text("0")
h.await_text("1")
sc = h.screenshot()
assert "T" not in sc
assert "5" not in sc
h.default_timeout = 4
h.write("Z")
h.press("Enter")
sleep(3)
h.await_text("T")
sc = h.screenshot()
assert "T" in sc
assert "5" in sc


def test_pymatrix_no_zero_one_running():
with Runner(*pymatrix_run("--test_mode"), width=100, height=50) as h:
h.await_text("T")
h.write("Z")
h.press("Enter")
sleep(2)
h.default_timeout = 3
h.await_text("T")
sc = h.screenshot()
for letter in "AaBbCcDe0987654321ZzRrOoPpQqWweEYyUuIiOoPpKkLlJjmMnNXxSsgGhH":
assert letter not in sc
7 changes: 7 additions & 0 deletions tests/test_single_line_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,10 @@ def test_set_test_mode_ext(mode, ext, expected_result):
def test_set_extended_chars(state, expected):
pymatrix.SingleLine.set_extended_chars(state)
assert pymatrix.SingleLine.char_list == expected


def test_zero_and_one():
pymatrix.SingleLine.set_zero_one(True)
assert pymatrix.SingleLine.char_list == ["0", "1"]
pymatrix.SingleLine.set_zero_one(False)
assert pymatrix.SingleLine.char_list == pymatrix.CHAR_LIST

0 comments on commit 4177102

Please sign in to comment.