This repository has been archived on 2024-07-30. You can view files and clone it, but cannot push or open issues or pull requests.
python-aternos/tests/files.py

33 lines
626 B
Python
Raw Permalink Normal View History

from pathlib import Path
from typing import List
abs_dir = Path(__file__).absolute().parent
samples = abs_dir / 'samples'
2023-01-13 15:23:27 +03:00
htmls = samples / 'html'
def read_sample(name: str) -> List[str]:
path = samples / name
if not path.exists():
return []
with path.open('rt', encoding='utf-8') as file:
return file \
.read() \
.strip() \
.replace('\r\n', '\n') \
.split('\n')
2023-01-13 15:23:27 +03:00
def read_html(name: str) -> bytes:
path = samples / 'html' / name
2023-01-13 15:23:27 +03:00
if not path.exists():
return b''
2023-01-13 15:23:27 +03:00
with path.open('rb') as file:
return file.read()