Skip to content

Commit

Permalink
solar - no engine. Simplified test setUp/tearDown, min args
Browse files Browse the repository at this point in the history
  • Loading branch information
valhuber committed Dec 11, 2020
1 parent b43c4a9 commit 3c22a09
Show file tree
Hide file tree
Showing 17 changed files with 19 additions and 38 deletions.
4 changes: 3 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@ allocate a payment to a set of outstanding orders

0.2.0 - Minor design refactoring of allocation

0.3.0 - Include logic_bank.extensions (allocation), constraint exceptions raised as ConstraintExceptions
0.3.0 - Include logic_bank.extensions (allocation), constraint exceptions raised as ConstraintExceptions

0.4.0 - Eliminate "engine" from runtime, to faciliate use in servers. Rework nw tests to centralize open logic in setup().
5 changes: 0 additions & 5 deletions logic_bank/exec_row_logic/logic_row.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ def __init__(self, row: base, old_row: base, ins_upd_dlt: str, nest_level: int,
rb = RuleBank()
self.rb = rb
self.session = a_session
# solar no engine self.session = rb.session; self.engine = rb._engine
self.some_base = declarative_base()

self.name = type(self.row).__name__ # class name (not table name)
Expand All @@ -66,10 +65,6 @@ def __init__(self, row: base, old_row: base, ins_upd_dlt: str, nest_level: int,
else:
self.table_meta = inspect(self.row)
self.log_engine("Restriction: Class Name must equal Table Name: " + self.name)
""" solar no engine
if self.engine is not None: # e.g, for testing legacy logic (no RuleBank)
self.inspector = Inspector.from_engine(self.engine)
"""

def get_attr_name(self, mapper, attr)-> str:
"""polymorhpism is for wimps - find the name
Expand Down
5 changes: 2 additions & 3 deletions logic_bank/logic_bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,9 @@ def activate(session: session, activator: callable):
:param activator: function that declares rules (e.g., Rule.sum...)
"""

# solar engine = session.bind.engine
rule_bank_setup.setup(session) # solar , engine)
rule_bank_setup.setup(session)
activator()
rule_bank_setup.compute_formula_execution_order() # solar session, engine)
rule_bank_setup.compute_formula_execution_order()


class Rule:
Expand Down
7 changes: 0 additions & 7 deletions logic_bank/rule_bank/rule_bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,6 @@ class RuleBank(metaclass=Singleton): # FIXME design review singleton
""" Dict[mapped_class: str, List[TablesRules]] -- rules for a table """
_at = datetime.now()

""" solar - no engine
_metadata = None
_base = None
_session = None
_engine = None
"""

def __init__(self):
self._metadata = None

Expand Down
12 changes: 2 additions & 10 deletions logic_bank/rule_bank/rule_bank_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,19 @@
from sqlalchemy.orm import session


def setup(a_session: session): # solar , an_engine: Engine):
def setup(a_session: session):
"""
Create the RuleBank
Register before_flush listeners
"""
rules_bank = RuleBank()
# rules_bank._session = a_session """ solar no rb.session... """
event.listen(a_session, "before_flush", before_flush)
event.listen(a_session, "before_commit", before_commit)

rules_bank.orm_objects = {}
rules_bank._at = datetime.now()

""" solar no engine...
rules_bank._engine = an_engine
rules_bank._metadata = MetaData(bind=an_engine, reflect=True)
from sqlalchemy.ext.declarative import declarative_base
rules_bank._base = declarative_base()
"""
return


Expand Down Expand Up @@ -77,7 +69,7 @@ def compute_formula_execution_order_for_class(class_name: str):
raise Exception("Mapped Class[" + class_name + "] blocked by circular dependencies:" + cycles)


def compute_formula_execution_order() -> bool: # solar, a_session: sessionengine: Engine):
def compute_formula_execution_order() -> bool:
"""
Determine formula execution order based on "row.xx" references (dependencies),
(or raise exception if cycles detected).
Expand Down
2 changes: 1 addition & 1 deletion nw/tests/test_add_cust.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import datetime

(did_fix_path, sys_env_info) = \
logic_bank_utils.add_python_path(project_dir="LogicBank", my_file=__file__)
logic_bank_utils.add_python_path(project_dir="LogicBank*", my_file=__file__)

if __name__ == '__main__':
print("\nStarted from cmd line - launch unittest and exit\n")
Expand Down
2 changes: 1 addition & 1 deletion nw/tests/test_add_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import datetime

(did_fix_path, sys_env_info) = \
logic_bank_utils.add_python_path(project_dir="LogicBank", my_file=__file__)
logic_bank_utils.add_python_path(project_dir="LogicBank*", my_file=__file__)

if __name__ == '__main__':
print("\nStarted from cmd line - launch unittest and exit\n")
Expand Down
2 changes: 1 addition & 1 deletion nw/tests/test_dlt_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from decimal import Decimal

(did_fix_path, sys_env_info) = \
logic_bank_utils.add_python_path(project_dir="LogicBank", my_file=__file__)
logic_bank_utils.add_python_path(project_dir="LogicBank*", my_file=__file__)

if __name__ == '__main__':
print("\nStarted from cmd line - launch unittest and exit\n")
Expand Down
2 changes: 1 addition & 1 deletion nw/tests/test_upd_employee_salary.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from decimal import Decimal

(did_fix_path, sys_env_info) = \
logic_bank_utils.add_python_path(project_dir="LogicBank", my_file=__file__)
logic_bank_utils.add_python_path(project_dir="LogicBank*", my_file=__file__)

if __name__ == '__main__':
print("\nStarted from cmd line - launch unittest and exit\n")
Expand Down
2 changes: 1 addition & 1 deletion nw/tests/test_upd_order_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from datetime import datetime

(did_fix_path, sys_env_info) = \
logic_bank_utils.add_python_path(project_dir="LogicBank", my_file=__file__)
logic_bank_utils.add_python_path(project_dir="LogicBank*", my_file=__file__)

if __name__ == '__main__':
print("\nStarted from cmd line - launch unittest and exit\n")
Expand Down
2 changes: 1 addition & 1 deletion nw/tests/test_upd_order_required.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from decimal import Decimal

(did_fix_path, sys_env_info) = \
logic_bank_utils.add_python_path(project_dir="LogicBank", my_file=__file__)
logic_bank_utils.add_python_path(project_dir="LogicBank*", my_file=__file__)

if __name__ == '__main__':
print("\nStarted from cmd line - launch unittest and exit\n")
Expand Down
2 changes: 1 addition & 1 deletion nw/tests/test_upd_order_reuse.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from decimal import Decimal

(did_fix_path, sys_env_info) = \
logic_bank_utils.add_python_path(project_dir="LogicBank", my_file=__file__)
logic_bank_utils.add_python_path(project_dir="LogicBank*", my_file=__file__)

if __name__ == '__main__':
print("\nStarted from cmd line - launch unittest and exit\n")
Expand Down
2 changes: 1 addition & 1 deletion nw/tests/test_upd_order_shipped.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from decimal import Decimal

(did_fix_path, sys_env_info) = \
logic_bank_utils.add_python_path(project_dir="LogicBank", my_file=__file__)
logic_bank_utils.add_python_path(project_dir="LogicBank*", my_file=__file__)

if __name__ == '__main__':
print("\nStarted from cmd line - launch unittest and exit\n")
Expand Down
2 changes: 1 addition & 1 deletion nw/tests/test_upd_order_shipped_auto_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from decimal import Decimal

(did_fix_path, sys_env_info) = \
logic_bank_utils.add_python_path(project_dir="LogicBank", my_file=__file__)
logic_bank_utils.add_python_path(project_dir="LogicBank*", my_file=__file__)

if __name__ == '__main__':
print("\nStarted from cmd line - launch unittest and exit\n")
Expand Down
2 changes: 1 addition & 1 deletion nw/tests/test_upd_orderclass_required.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from decimal import Decimal

(did_fix_path, sys_env_info) = \
logic_bank_utils.add_python_path(project_dir="LogicBank", my_file=__file__)
logic_bank_utils.add_python_path(project_dir="LogicBank*", my_file=__file__)

if __name__ == '__main__':
print("\nStarted from cmd line - launch unittest and exit\n")
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ six==1.15.0
SQLAlchemy==1.3.20
SQLAlchemy-Utils==0.36.8
Flask-AppBuilder==3.1.1
LogicBankUtils==0.5.0
LogicBankUtils
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def desc():

setup(
name="logicbank",
version="0.3.0",
version="0.4.0",
url="https://github.com/valhuber/logicbank",
license="BSD",
author="Val Huber",
Expand Down

0 comments on commit 3c22a09

Please sign in to comment.