Parser factory chooses parser class based on filepath 🟥

This commit is contained in:
Daniel Roth 2026-01-19 11:08:30 +00:00
parent e277e270ab
commit c073a4cb43
6 changed files with 40 additions and 2 deletions

View file

@ -0,0 +1,4 @@
from backend.condition.parsing.parser import Parser
def select_parser(filepath: str) -> Parser:
raise NotImplementedError

View file

@ -0,0 +1,8 @@
from typing import BinaryIO, Any
from backend.condition.parsing.parser import Parser
class LbwfParser(Parser):
def parse(self, file_stream: BinaryIO) -> Any:
raise NotImplementedError

View file

@ -0,0 +1,8 @@
from abc import ABC, abstractmethod
from typing import BinaryIO, Any
class Parser(ABC):
@abstractmethod
def parse(self, file_stream: BinaryIO) -> Any:
pass

View file

@ -3,4 +3,10 @@ from typing import BinaryIO, List
from utils.logger import setup_logger
def process_file(file_stream: BinaryIO, source_key: str) -> None:
print(f"[processor] Received file: {source_key}")
print(f"[processor] Received file: {source_key}")
# Instantiation
# Orchestration

View file

@ -0,0 +1,12 @@
from backend.condition.parsing.factory import select_parser
def test_selects_lbwf_parser():
# arrange
file_path_str = "uploads/lbwf/Example Asset Data.xlsx"
expected_class_name = "LbwfParser"
# act
actual_class_name = select_parser(file_path_str).__class__.__name__
# assert
assert expected_class_name == actual_class_name

View file

@ -1,4 +1,4 @@
[pytest]
pythonpath = .
addopts = --cov-report term-missing --cov=etl/epc --cov=recommendations --cov=backend --cov=etl/epc_clean --cov=etl/spatial
testpaths = recommendations/tests backend/tests etl/epc/tests etl/epc_clean/tests etl/spatial/tests
testpaths = recommendations/tests backend/tests etl/epc/tests etl/epc_clean/tests etl/spatial/tests backend/condition/tests