Publish workflow #4
@@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
def readlines(path: str) -> list[str]:
|
||||||
|
with open(path, "r") as fid:
|
||||||
|
lines = fid.readlines()
|
||||||
|
return lines
|
||||||
|
|
||||||
|
def read(path: str) -> str:
|
||||||
|
return "".join(readlines(path))
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from utils.misc import read, readlines
|
||||||
|
|
||||||
|
CWD = Path(__file__).parent.resolve()
|
||||||
|
TEST_DATA_DIR = CWD / "data"
|
||||||
|
TEST_FILE_PATH = TEST_DATA_DIR / "text.txt"
|
||||||
|
|
||||||
|
EXPECTED_TEST = """This is a test file
|
||||||
|
with a second line
|
||||||
|
and a third line
|
||||||
|
"""
|
||||||
|
|
||||||
|
def test_readlines_str():
|
||||||
|
result = readlines(TEST_FILE_PATH)
|
||||||
|
assert result
|
||||||
|
assert isinstance(result, list)
|
||||||
|
assert all(isinstance(element, str) for element in result)
|
||||||
|
assert result[1].strip() == "with a second line"
|
||||||
|
|
||||||
|
def test_path_str():
|
||||||
|
result = read(TEST_FILE_PATH)
|
||||||
|
assert result
|
||||||
|
assert isinstance(result, str)
|
||||||
|
assert result == EXPECTED_TEST
|
||||||
Reference in New Issue
Block a user