コード例 #1
0
ファイル: test_register.py プロジェクト: Tasse00/pydi
    def test_register(self):
        ctx = NewContext()
        ctx.register(Restaurant,
                     id="rest",
                     refs={"manager": IdRef('manager-staff')})
        ctx.register(Kitchen, refs={'staff': IdRef('kitchen-staff')})
        ctx.register(Cashier, refs={'staff': IdRef('manager-staff')})
        ctx.register(EatingRoom, refs={'staff': IdRef('eatingroom-staff')})
        ctx.register(Seat)
        ctx.register(Staff,
                     id='kitchen-staff',
                     consts={'name': 'kitchen-staff'})
        ctx.register(Staff,
                     id='eatingroom-staff',
                     consts={'name': 'eatingroom-staff'})
        ctx.register(Staff,
                     id='manager-staff',
                     consts={'name': 'manager-staff'})

        rest: Restaurant = ctx.instance_by_id("rest")

        self.assertEqual(rest.manager.name, 'manager-staff')
        self.assertEqual(rest.kitchen.staff.name, 'kitchen-staff')
        self.assertEqual(rest.kitchen.number, 1)
        self.assertEqual(rest.cashier.staff, rest.manager)
        self.assertEqual(rest.eatingroom.staff.name, 'eatingroom-staff')
        self.assertEqual(rest.eatingroom.seat.id, 'default-seat')

        self.assertEqual(rest, ctx.instance_by_cls(Restaurant))
コード例 #2
0
ファイル: test_register.py プロジェクト: Tasse00/pydi
    def test_register_to_xml(self):
        ctx = NewContext()
        ctx.register(Restaurant,
                     id="rest",
                     refs={"manager": IdRef('manager-staff')})
        ctx.register(Kitchen, refs={'staff': IdRef('kitchen-staff')})
        ctx.register(Cashier, refs={'staff': IdRef('manager-staff')})
        ctx.register(EatingRoom, refs={'staff': IdRef('eatingroom-staff')})
        ctx.register(Seat)
        ctx.register(Staff,
                     id='kitchen-staff',
                     consts={'name': 'kitchen-staff'})
        ctx.register(Staff,
                     id='eatingroom-staff',
                     consts={'name': 'eatingroom-staff'})
        ctx.register(Staff,
                     id='manager-staff',
                     consts={'name': 'manager-staff'})

        self.assertEqual(self.xml_file.read_text(),
                         ctx.format_beans_xml(indent="    "))
コード例 #3
0
ファイル: __init__.py プロジェクト: Tasse00/pydi
from di.decorator import bean
from di.ref import IdRef
from tests.app.cashier import Cashier
from tests.app.eatingroom import EatingRoom
from tests.app.kitchen import Kitchen
from tests.app.staff import Staff
'''
@bean 装饰器仅用于测试register_group. 对于register及register_file无影响
'''


@bean(id="rest", refs={"manager": IdRef("manager-staff")})
class Restaurant:
    def __init__(self, manager: Staff, kitchen: Kitchen,
                 eatingroom: EatingRoom, cashier: Cashier):
        self.manager = manager
        self.kitchen = kitchen
        self.eatingroom = eatingroom
        self.cashier = cashier
コード例 #4
0
from dataclasses import dataclass

from di.decorator import bean
from di.ref import IdRef
from tests.app_dc.cashier import Cashier
from tests.app_dc.eatingroom import EatingRoom
from tests.app_dc.kitchen import Kitchen
from tests.app_dc.staff import Staff
'''
@bean 装饰器仅用于测试register_group. 对于register及register_file无影响
'''


@bean(id="rest", refs={"manager": IdRef("manager-staff")}, group="dc")
@dataclass
class Restaurant:
    manager: Staff
    kitchen: Kitchen
    eatingroom: EatingRoom
    cashier: Cashier
コード例 #5
0
ファイル: ctx.py プロジェクト: Tasse00/pydi
 def instance_by_id(self, id: str):
     return self.instance(IdRef(id))
コード例 #6
0
ファイル: eatingroom.py プロジェクト: Tasse00/pydi
from di.decorator import bean
from di.ref import IdRef
from tests.app.seat import Seat
from tests.app.staff import Staff


@bean(refs={'staff': IdRef('eatingroom-staff')})
class EatingRoom:
    def __init__(self, staff: Staff, seat: Seat):
        # @TODO properties中的list好了后,可以将staff及seat修改为 List
        self.staff = staff
        self.seat = seat
コード例 #7
0
from dataclasses import dataclass

from di.decorator import bean
from di.ref import IdRef
from tests.app_dc.staff import Staff


@bean(refs={'staff': IdRef('kitchen-staff')}, group="dc")
@dataclass
class Kitchen:
    staff: Staff
    number: int = 1
コード例 #8
0
from di.decorator import bean
from di.ref import IdRef
from tests.app.staff import Staff


@bean(refs={'staff': IdRef('manager-staff')})
class Cashier:
    def __init__(self, staff: Staff):
        self.staff = staff
コード例 #9
0
from dataclasses import dataclass

from di.decorator import bean
from di.ref import IdRef
from tests.app_dc.staff import Staff


@bean(refs={'staff': IdRef('manager-staff')}, group="dc")
@dataclass
class Cashier:
    staff: Staff
コード例 #10
0
from dataclasses import dataclass

from di.decorator import bean
from di.ref import IdRef
from tests.app_dc.seat import Seat
from tests.app_dc.staff import Staff


@bean(refs={'staff': IdRef('eatingroom-staff')}, group="dc")
@dataclass
class EatingRoom:
    staff: Staff
    seat: Seat
    # @TODO properties中的list好了后,可以将staff及seat修改为 List

コード例 #11
0
from di.decorator import bean
from di.ref import IdRef
from tests.app.staff import Staff


@bean(refs={'staff': IdRef('kitchen-staff')})
class Kitchen:
    def __init__(self, staff: Staff, number: int = 1):
        self.staff = staff
        self.number = number