Create FileType enum 🟪

This commit is contained in:
Daniel Roth 2026-01-19 11:47:32 +00:00
parent 6fd4b19e88
commit 049a93fa26
5 changed files with 43 additions and 17 deletions

View 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")

View file

@ -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")

View file

@ -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

View file

@ -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

View 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)