mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Parser factory chooses parser class based on filepath 🟥
This commit is contained in:
parent
e277e270ab
commit
c073a4cb43
6 changed files with 40 additions and 2 deletions
4
backend/condition/parsing/factory.py
Normal file
4
backend/condition/parsing/factory.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
from backend.condition.parsing.parser import Parser
|
||||
|
||||
def select_parser(filepath: str) -> Parser:
|
||||
raise NotImplementedError
|
||||
8
backend/condition/parsing/lbwf_parser.py
Normal file
8
backend/condition/parsing/lbwf_parser.py
Normal 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
|
||||
8
backend/condition/parsing/parser.py
Normal file
8
backend/condition/parsing/parser.py
Normal 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
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
12
backend/condition/tests/parsing/test_parsing_factory.py
Normal file
12
backend/condition/tests/parsing/test_parsing_factory.py
Normal 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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue