mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Create FileType enum 🟪
This commit is contained in:
parent
6fd4b19e88
commit
049a93fa26
5 changed files with 43 additions and 17 deletions
12
backend/condition/file_type.py
Normal file
12
backend/condition/file_type.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
from enum import Enum
|
||||
|
||||
class FileType(Enum):
|
||||
LBWF = "lbwf"
|
||||
|
||||
def detect_file_type(filepath: str) -> FileType:
|
||||
path = filepath.lower()
|
||||
|
||||
if "lbwf" in path:
|
||||
return FileType.LBWF
|
||||
|
||||
raise ValueError("Unrecognised file path")
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
from backend.condition.file_type import FileType
|
||||
from backend.condition.parsing.parser import Parser
|
||||
from backend.condition.parsing.lbwf_parser import LbwfParser
|
||||
|
||||
def select_parser(filepath: str) -> Parser:
|
||||
path = filepath.lower()
|
||||
|
||||
if "lbwf" in path:
|
||||
def select_parser(file_type: FileType) -> Parser:
|
||||
if file_type is FileType.LBWF:
|
||||
return LbwfParser()
|
||||
|
||||
raise ValueError("Unrecognised file path, unable to instantiate Parser")
|
||||
raise ValueError("Unrecognised file type, unable to instantiate Parser")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
from typing import BinaryIO, List
|
||||
|
||||
from utils.logger import setup_logger
|
||||
from backend.condition.file_type import FileType
|
||||
|
||||
def process_file(file_stream: BinaryIO, source_key: str) -> None:
|
||||
print(f"[processor] Received file: {source_key}")
|
||||
|
|
@ -9,4 +10,3 @@ def process_file(file_stream: BinaryIO, source_key: str) -> None:
|
|||
|
||||
|
||||
# Orchestration
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +1,15 @@
|
|||
import pytest
|
||||
|
||||
from backend.condition.parsing.factory import select_parser
|
||||
from backend.condition.file_type import FileType
|
||||
|
||||
def test_selects_lbwf_parser():
|
||||
# arrange
|
||||
file_path_str = "uploads/lbwf/Example Asset Data.xlsx"
|
||||
file_type = FileType.LBWF
|
||||
expected_class_name = "LbwfParser"
|
||||
|
||||
# act
|
||||
actual_class_name = select_parser(file_path_str).__class__.__name__
|
||||
actual_class_name = select_parser(file_type).__class__.__name__
|
||||
|
||||
# assert
|
||||
assert expected_class_name == actual_class_name
|
||||
|
||||
def test_unknown_filepath_raises_value_error():
|
||||
# arrange
|
||||
file_path_str = "unkown/Example Asset Data.xlsx"
|
||||
|
||||
# act + assert
|
||||
with pytest.raises(ValueError):
|
||||
select_parser(file_path_str)
|
||||
assert expected_class_name == actual_class_name
|
||||
22
backend/condition/tests/test_detect_file_type.py
Normal file
22
backend/condition/tests/test_detect_file_type.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import pytest
|
||||
|
||||
from backend.condition.file_type import FileType, detect_file_type
|
||||
|
||||
def test_detects_lbwf_file_type():
|
||||
# arrange
|
||||
file_path_str = "uploads/lbwf/Exaple Asset Data.xlsx"
|
||||
expected_file_type = FileType.LBWF
|
||||
|
||||
# act
|
||||
actual_file_type: FileType = detect_file_type(file_path_str)
|
||||
|
||||
# assert
|
||||
assert expected_file_type == actual_file_type
|
||||
|
||||
def test_unknown_filepath_raises_value_error():
|
||||
# arrange
|
||||
file_path_str = "unknown/Example Asset Data.xlsx"
|
||||
|
||||
# act + assert
|
||||
with pytest.raises(ValueError):
|
||||
detect_file_type(file_path_str)
|
||||
Loading…
Add table
Reference in a new issue