adding subclass functionality (#16) · LatvianPython/pyoracle_forms@28983ca · GitHub
Skip to content

Commit 28983ca

Browse files
adding subclass functionality (#16)
1 parent bdf7efc commit 28983ca

6 files changed

Lines changed: 75 additions & 3 deletions

File tree

pyoracle_forms/__init__.py

Lines changed: 1 addition & 1 deletion

pyoracle_forms/context.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,15 @@ def object_number(obj_name: str) -> int:
234234
"d2fobgcv_GetConstValue", (c_char_p, c_void_p), return_value_index=1
235235
)(obj_name.encode("utf-8"), c_int()).value
236236
)
237+
238+
239+
def subclass(
240+
to_subclass: BaseObject, parent: BaseObject, keep_path: bool = False
241+
) -> None:
242+
handled_api_function("d2fobsc_SubClass", (c_void_p, c_void_p, c_bool))(
243+
to_subclass, parent, keep_path
244+
)
245+
246+
247+
def un_subclass(to_un_subclass: BaseObject) -> None:
248+
handled_api_function("d2fobus_UnSubClass", (c_void_p,))(to_un_subclass)

pyoracle_forms/generic_object.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
from .context import create
1111
from .context import destroy
1212
from .context import has_property
13+
from .context import un_subclass
14+
from .context import subclass
1315

1416

1517
class FormsObjects(enum.Enum):
@@ -79,12 +81,23 @@ def destroy(self) -> None:
7981
destroy(self)
8082
self._as_parameter_ = c_void_p(0)
8183

84+
def un_subclass(self) -> None:
85+
un_subclass(self)
86+
87+
def subclass(self, property_class: BaseObject, keep_path: bool = False) -> None:
88+
subclass(self, property_class, keep_path)
89+
8290
def __repr__(self) -> str:
8391
return f"{self.__class__.__name__}({repr(self._as_parameter_)})"
8492

8593
def __bool__(self) -> bool:
8694
return bool(self._as_parameter_)
8795

96+
def __eq__(self, other: object) -> bool:
97+
if not isinstance(other, BaseObject):
98+
return NotImplemented
99+
return self._as_parameter_ == other._as_parameter_
100+
88101

89102
class GenericObject(BaseObject):
90103
@classmethod

tests/conftest.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@
22

33
import pytest
44

5-
from pyoracle_forms import Module, Item, DataBlock, Canvas, Window, initialize_context
5+
from pyoracle_forms import (
6+
Module,
7+
Item,
8+
DataBlock,
9+
Canvas,
10+
Window,
11+
initialize_context,
12+
PropertyClass,
13+
)
614
from pyoracle_forms import context as ctx
715

816

@@ -25,10 +33,21 @@ def data_block(module):
2533

2634

2735
@pytest.fixture(scope="session")
28-
def item(data_block):
36+
def item(data_block) -> Item:
2937
return data_block.items[0]
3038

3139

40+
@pytest.fixture(scope="session")
41+
def property_classes(module) -> [PropertyClass]:
42+
return module.property_classes
43+
44+
45+
@pytest.fixture(scope="session")
46+
def property_class(property_classes) -> PropertyClass:
47+
assert property_classes
48+
return property_classes[0]
49+
50+
3251
@pytest.fixture(scope="session")
3352
def canvas(module):
3453
return module.canvases[0]
@@ -92,3 +111,10 @@ def new_data_block(make_data_block):
92111
@pytest.fixture(scope="function")
93112
def new_item(new_data_block, make_item):
94113
return make_item(new_data_block, "ITM")
114+
115+
116+
@pytest.fixture(scope="function")
117+
def subclassed_item(new_data_block, make_item, property_class):
118+
item = make_item(new_data_block, "ITM")
119+
item.subclass(property_class)
120+
return item

tests/test_item.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,11 @@ def test_can_delete_items(data_block, make_item):
3838

3939
data_block.items[0].destroy()
4040
assert len(data_block.items) < items
41+
42+
43+
def test_equality(data_block):
44+
assert data_block.items[0] == data_block.items[0]
45+
46+
47+
def test_inequality(data_block, make_item):
48+
assert make_item(data_block, "ITM_1") != make_item(data_block, "ITM_2")

tests/test_subclass.py

Lines changed: 13 additions & 0 deletions

0 commit comments

Comments
 (0)