Skip to content

Commit

Permalink
Flush out tests and fix issue with set_server_config
Browse files Browse the repository at this point in the history
  • Loading branch information
Eeems committed Mar 14, 2024
1 parent 510f432 commit 8655616
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 28 deletions.
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ test: $(VENV_BIN_ACTIVATE) .venv/${FW_VERSION}_reMarkable2-${FW_DATA}.signed
@echo "[info] Running test"
. $(VENV_BIN_ACTIVATE); \
python test.py
if [ -d .venv/mnt ] && mountpoint -q .venv/mnt; then \
umount -ql .venv/mnt; \
fi
mkdir -p .venv/mnt
. $(VENV_BIN_ACTIVATE); \
python -m codexctl mount --out .venv/mnt ".venv/${FW_VERSION}_reMarkable2-${FW_DATA}.signed"
mountpoint .venv/mnt
umount -ql .venv/mnt
# if [ -d .venv/mnt ] && mountpoint -q .venv/mnt; then \
# umount -ql .venv/mnt; \
# fi
# mkdir -p .venv/mnt
# . $(VENV_BIN_ACTIVATE); \
# python -m codexctl mount --out .venv/mnt ".venv/${FW_VERSION}_reMarkable2-${FW_DATA}.signed"
# mountpoint .venv/mnt
# umount -ql .venv/mnt

clean:
@echo "[info] Cleaning"
Expand Down
8 changes: 4 additions & 4 deletions codexctl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,11 +142,11 @@ def set_server_config(contents, server_host_name):
data_attributes = contents.split("\n")
line = 0

logger.debug(f"Contents are: {contents}")
logger.debug(f"Contents are:\n{contents}")

for i in range(0, len(data_attributes)):
if data_attributes[i].startswith("[GENERAL]"):
logger.debug("Found GENERAL= line")
if data_attributes[i].startswith("[General]"):
logger.debug("Found [General] line")
line = i + 1
if not data_attributes[i].startswith("SERVER="):
continue
Expand All @@ -157,7 +157,7 @@ def set_server_config(contents, server_host_name):
data_attributes.insert(line, f"SERVER={server_host_name}")
converted = "\n".join(data_attributes)

logger.debug("Converted contents are: {converted}")
logger.debug(f"Converted contents are:\n{converted}")

return converted

Expand Down
61 changes: 45 additions & 16 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,37 +1,66 @@
import sys
import difflib
import codexctl

FAILED = False

print("Testing set_server_config: ", end="")
result = codexctl.set_server_config(
"""
[General]

def test_set_server_config(original, expected):
global FAILED
print("Testing set_server_config: ", end="")
result = codexctl.set_server_config(original, "test")
if result == expected:
print("pass")
return

FAILED = True
print("fail")
for diff in difflib.ndiff(expected.splitlines(), result.splitlines()):
print(f" {diff}")


test_set_server_config(
"",
"SERVER=test\n",
)

test_set_server_config(
"""[General]
#REMARKABLE_RELEASE_APPID={98DA7DF2-4E3E-4744-9DE6-EC931886ABAB}
#SERVER=https://updates.cloud.remarkable.engineering/service/update2
#GROUP=Prod
#PLATFORM=reMarkable2
REMARKABLE_RELEASE_VERSION=3.9.5.2026
""",
"test",
)
if (
result
== """
[General]
"""[General]
SERVER=test
#REMARKABLE_RELEASE_APPID={98DA7DF2-4E3E-4744-9DE6-EC931886ABAB}
#SERVER=https://updates.cloud.remarkable.engineering/service/update2
#GROUP=Prod
#PLATFORM=reMarkable2
REMARKABLE_RELEASE_VERSION=3.9.5.2026
"""
):
FAILED = True
print("fail")
""",
)

else:
print("pass")
test_set_server_config(
"""[General]
SERVER=testing
#REMARKABLE_RELEASE_APPID={98DA7DF2-4E3E-4744-9DE6-EC931886ABAB}
#SERVER=https://updates.cloud.remarkable.engineering/service/update2
#GROUP=Prod
#PLATFORM=reMarkable2
REMARKABLE_RELEASE_VERSION=3.9.5.2026
""",
"""[General]
SERVER=test
#SERVER=testing
#REMARKABLE_RELEASE_APPID={98DA7DF2-4E3E-4744-9DE6-EC931886ABAB}
#SERVER=https://updates.cloud.remarkable.engineering/service/update2
#GROUP=Prod
#PLATFORM=reMarkable2
REMARKABLE_RELEASE_VERSION=3.9.5.2026
""",
)

if FAILED:
sys.exit(1)

0 comments on commit 8655616

Please sign in to comment.