py10x-universe 0.1.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. core_10x/__init__.py +42 -0
  2. core_10x/backbone/__init__.py +0 -0
  3. core_10x/backbone/backbone_store.py +59 -0
  4. core_10x/backbone/backbone_traitable.py +30 -0
  5. core_10x/backbone/backbone_user.py +66 -0
  6. core_10x/backbone/bound_data_domain.py +49 -0
  7. core_10x/backbone/namespace.py +101 -0
  8. core_10x/backbone/vault.py +38 -0
  9. core_10x/code_samples/__init__.py +0 -0
  10. core_10x/code_samples/_package_manifest.py +3 -0
  11. core_10x/code_samples/directories.py +181 -0
  12. core_10x/code_samples/person.py +76 -0
  13. core_10x/concrete_traits.py +356 -0
  14. core_10x/conftest.py +12 -0
  15. core_10x/curve.py +321 -0
  16. core_10x/data_domain.py +48 -0
  17. core_10x/data_domain_binder.py +45 -0
  18. core_10x/directory.py +250 -0
  19. core_10x/entity.py +8 -0
  20. core_10x/entity_filter.py +5 -0
  21. core_10x/environment_variables.py +147 -0
  22. core_10x/exec_control.py +84 -0
  23. core_10x/experimental/__init__.py +0 -0
  24. core_10x/experimental/data_protocol_ex.py +34 -0
  25. core_10x/global_cache.py +121 -0
  26. core_10x/manual_tests/__init__.py +0 -0
  27. core_10x/manual_tests/calendar_test.py +35 -0
  28. core_10x/manual_tests/ctor_update_bug.py +58 -0
  29. core_10x/manual_tests/debug_graph_on.py +17 -0
  30. core_10x/manual_tests/debug_graphoff_inside_graph_on.py +28 -0
  31. core_10x/manual_tests/enum_bits_test.py +17 -0
  32. core_10x/manual_tests/env_vars_trivial_test.py +12 -0
  33. core_10x/manual_tests/existing_traitable.py +33 -0
  34. core_10x/manual_tests/k10x_test1.py +13 -0
  35. core_10x/manual_tests/named_constant_test.py +121 -0
  36. core_10x/manual_tests/nucleus_trivial_test.py +42 -0
  37. core_10x/manual_tests/polars_test.py +14 -0
  38. core_10x/manual_tests/py_class_test.py +4 -0
  39. core_10x/manual_tests/rc_test.py +42 -0
  40. core_10x/manual_tests/rdate_test.py +12 -0
  41. core_10x/manual_tests/reference_serialization_bug.py +19 -0
  42. core_10x/manual_tests/resource_trivial_test.py +10 -0
  43. core_10x/manual_tests/store_uri_test.py +6 -0
  44. core_10x/manual_tests/trait_definition_test.py +19 -0
  45. core_10x/manual_tests/trait_filter_test.py +15 -0
  46. core_10x/manual_tests/trait_flag_modification_test.py +42 -0
  47. core_10x/manual_tests/trait_modification_bug.py +26 -0
  48. core_10x/manual_tests/traitable_as_of_test.py +82 -0
  49. core_10x/manual_tests/traitable_heir_test.py +39 -0
  50. core_10x/manual_tests/traitable_history_test.py +41 -0
  51. core_10x/manual_tests/traitable_serialization_test.py +54 -0
  52. core_10x/manual_tests/traitable_trivial_test.py +71 -0
  53. core_10x/manual_tests/trivial_graph_test.py +16 -0
  54. core_10x/manual_tests/ts_class_association_test.py +64 -0
  55. core_10x/manual_tests/ts_trivial_test.py +35 -0
  56. core_10x/named_constant.py +425 -0
  57. core_10x/nucleus.py +81 -0
  58. core_10x/package_manifest.py +85 -0
  59. core_10x/package_refactoring.py +153 -0
  60. core_10x/py_class.py +431 -0
  61. core_10x/rc.py +155 -0
  62. core_10x/rdate.py +339 -0
  63. core_10x/resource.py +189 -0
  64. core_10x/roman_number.py +67 -0
  65. core_10x/testlib/__init__.py +0 -0
  66. core_10x/testlib/test_store.py +240 -0
  67. core_10x/testlib/traitable_history_tests.py +787 -0
  68. core_10x/testlib/ts_tests.py +280 -0
  69. core_10x/trait.py +377 -0
  70. core_10x/trait_definition.py +176 -0
  71. core_10x/trait_filter.py +205 -0
  72. core_10x/trait_method_error.py +36 -0
  73. core_10x/traitable.py +1082 -0
  74. core_10x/traitable_cli.py +153 -0
  75. core_10x/traitable_heir.py +33 -0
  76. core_10x/traitable_id.py +31 -0
  77. core_10x/ts_store.py +172 -0
  78. core_10x/ts_store_type.py +26 -0
  79. core_10x/ts_union.py +147 -0
  80. core_10x/ui_hint.py +153 -0
  81. core_10x/unit_tests/test_concrete_traits.py +156 -0
  82. core_10x/unit_tests/test_converters.py +51 -0
  83. core_10x/unit_tests/test_curve.py +157 -0
  84. core_10x/unit_tests/test_directory.py +54 -0
  85. core_10x/unit_tests/test_documentation.py +172 -0
  86. core_10x/unit_tests/test_environment_variables.py +15 -0
  87. core_10x/unit_tests/test_filters.py +239 -0
  88. core_10x/unit_tests/test_graph.py +348 -0
  89. core_10x/unit_tests/test_named_constant.py +98 -0
  90. core_10x/unit_tests/test_rc.py +11 -0
  91. core_10x/unit_tests/test_rdate.py +484 -0
  92. core_10x/unit_tests/test_trait_method_error.py +80 -0
  93. core_10x/unit_tests/test_trait_modification.py +19 -0
  94. core_10x/unit_tests/test_traitable.py +959 -0
  95. core_10x/unit_tests/test_traitable_history.py +1 -0
  96. core_10x/unit_tests/test_ts_store.py +1 -0
  97. core_10x/unit_tests/test_ts_union.py +369 -0
  98. core_10x/unit_tests/test_ui_nodes.py +81 -0
  99. core_10x/unit_tests/test_xxcalendar.py +471 -0
  100. core_10x/vault/__init__.py +0 -0
  101. core_10x/vault/sec_keys.py +133 -0
  102. core_10x/vault/security_keys_old.py +168 -0
  103. core_10x/vault/vault.py +56 -0
  104. core_10x/vault/vault_traitable.py +56 -0
  105. core_10x/vault/vault_user.py +70 -0
  106. core_10x/xdate_time.py +136 -0
  107. core_10x/xnone.py +71 -0
  108. core_10x/xxcalendar.py +228 -0
  109. infra_10x/__init__.py +0 -0
  110. infra_10x/manual_tests/__init__.py +0 -0
  111. infra_10x/manual_tests/test_misc.py +16 -0
  112. infra_10x/manual_tests/test_prepare_filter_and_pipeline.py +25 -0
  113. infra_10x/mongodb_admin.py +111 -0
  114. infra_10x/mongodb_store.py +346 -0
  115. infra_10x/mongodb_utils.py +129 -0
  116. infra_10x/unit_tests/conftest.py +13 -0
  117. infra_10x/unit_tests/test_mongo_db.py +36 -0
  118. infra_10x/unit_tests/test_mongo_history.py +1 -0
  119. py10x_universe-0.1.3.dist-info/METADATA +406 -0
  120. py10x_universe-0.1.3.dist-info/RECORD +214 -0
  121. py10x_universe-0.1.3.dist-info/WHEEL +4 -0
  122. py10x_universe-0.1.3.dist-info/licenses/LICENSE +21 -0
  123. ui_10x/__init__.py +0 -0
  124. ui_10x/apps/__init__.py +0 -0
  125. ui_10x/apps/collection_editor_app.py +100 -0
  126. ui_10x/choice.py +212 -0
  127. ui_10x/collection_editor.py +135 -0
  128. ui_10x/concrete_trait_widgets.py +220 -0
  129. ui_10x/conftest.py +8 -0
  130. ui_10x/entity_stocker.py +173 -0
  131. ui_10x/examples/__init__.py +0 -0
  132. ui_10x/examples/_guess_word_data.py +14076 -0
  133. ui_10x/examples/collection_editor.py +17 -0
  134. ui_10x/examples/date_selector.py +14 -0
  135. ui_10x/examples/entity_stocker.py +18 -0
  136. ui_10x/examples/guess_word.py +392 -0
  137. ui_10x/examples/message_box.py +20 -0
  138. ui_10x/examples/multi_choice.py +17 -0
  139. ui_10x/examples/py_data_browser.py +66 -0
  140. ui_10x/examples/radiobox.py +29 -0
  141. ui_10x/examples/single_choice.py +31 -0
  142. ui_10x/examples/style_sheet.py +47 -0
  143. ui_10x/examples/trivial_entity_editor.py +18 -0
  144. ui_10x/platform.py +20 -0
  145. ui_10x/platform_interface.py +517 -0
  146. ui_10x/py_data_browser.py +249 -0
  147. ui_10x/qt6/__init__.py +0 -0
  148. ui_10x/qt6/conftest.py +8 -0
  149. ui_10x/qt6/manual_tests/__init__.py +0 -0
  150. ui_10x/qt6/manual_tests/basic_test.py +35 -0
  151. ui_10x/qt6/platform_implementation.py +275 -0
  152. ui_10x/qt6/utils.py +665 -0
  153. ui_10x/rio/__init__.py +0 -0
  154. ui_10x/rio/apps/examples/examples/__init__.py +22 -0
  155. ui_10x/rio/apps/examples/examples/components/__init__.py +3 -0
  156. ui_10x/rio/apps/examples/examples/components/collection_editor.py +15 -0
  157. ui_10x/rio/apps/examples/examples/pages/collection_editor.py +21 -0
  158. ui_10x/rio/apps/examples/examples/pages/login_page.py +88 -0
  159. ui_10x/rio/apps/examples/examples/pages/style_sheet.py +21 -0
  160. ui_10x/rio/apps/examples/rio.toml +14 -0
  161. ui_10x/rio/component_builder.py +497 -0
  162. ui_10x/rio/components/__init__.py +9 -0
  163. ui_10x/rio/components/group_box.py +31 -0
  164. ui_10x/rio/components/labeled_checkbox.py +18 -0
  165. ui_10x/rio/components/line_edit.py +37 -0
  166. ui_10x/rio/components/radio_button.py +32 -0
  167. ui_10x/rio/components/separator.py +24 -0
  168. ui_10x/rio/components/splitter.py +121 -0
  169. ui_10x/rio/components/tree_view.py +75 -0
  170. ui_10x/rio/conftest.py +35 -0
  171. ui_10x/rio/internals/__init__.py +0 -0
  172. ui_10x/rio/internals/app.py +192 -0
  173. ui_10x/rio/manual_tests/__init__.py +0 -0
  174. ui_10x/rio/manual_tests/basic_test.py +24 -0
  175. ui_10x/rio/manual_tests/splitter.py +27 -0
  176. ui_10x/rio/platform_implementation.py +91 -0
  177. ui_10x/rio/style_sheet.py +53 -0
  178. ui_10x/rio/unit_tests/test_collection_editor.py +68 -0
  179. ui_10x/rio/unit_tests/test_internals.py +630 -0
  180. ui_10x/rio/unit_tests/test_style_sheet.py +37 -0
  181. ui_10x/rio/widgets/__init__.py +46 -0
  182. ui_10x/rio/widgets/application.py +109 -0
  183. ui_10x/rio/widgets/button.py +48 -0
  184. ui_10x/rio/widgets/button_group.py +60 -0
  185. ui_10x/rio/widgets/calendar.py +23 -0
  186. ui_10x/rio/widgets/checkbox.py +24 -0
  187. ui_10x/rio/widgets/dialog.py +137 -0
  188. ui_10x/rio/widgets/group_box.py +27 -0
  189. ui_10x/rio/widgets/layout.py +34 -0
  190. ui_10x/rio/widgets/line_edit.py +37 -0
  191. ui_10x/rio/widgets/list.py +105 -0
  192. ui_10x/rio/widgets/message_box.py +70 -0
  193. ui_10x/rio/widgets/scroll_area.py +31 -0
  194. ui_10x/rio/widgets/spacer.py +6 -0
  195. ui_10x/rio/widgets/splitter.py +45 -0
  196. ui_10x/rio/widgets/text_edit.py +28 -0
  197. ui_10x/rio/widgets/tree.py +89 -0
  198. ui_10x/rio/widgets/unit_tests/test_button.py +101 -0
  199. ui_10x/rio/widgets/unit_tests/test_button_group.py +33 -0
  200. ui_10x/rio/widgets/unit_tests/test_calendar.py +114 -0
  201. ui_10x/rio/widgets/unit_tests/test_checkbox.py +109 -0
  202. ui_10x/rio/widgets/unit_tests/test_group_box.py +158 -0
  203. ui_10x/rio/widgets/unit_tests/test_label.py +43 -0
  204. ui_10x/rio/widgets/unit_tests/test_line_edit.py +140 -0
  205. ui_10x/rio/widgets/unit_tests/test_list.py +146 -0
  206. ui_10x/table_header_view.py +305 -0
  207. ui_10x/table_view.py +174 -0
  208. ui_10x/trait_editor.py +189 -0
  209. ui_10x/trait_widget.py +131 -0
  210. ui_10x/traitable_editor.py +200 -0
  211. ui_10x/traitable_view.py +131 -0
  212. ui_10x/unit_tests/conftest.py +8 -0
  213. ui_10x/unit_tests/test_platform.py +9 -0
  214. ui_10x/utils.py +661 -0
@@ -0,0 +1,42 @@
1
+ from core_10x.trait_definition import M
2
+ from core_10x.traitable import T, Traitable
3
+ from core_10x.xnone import XNone
4
+
5
+
6
+ class X(Traitable):
7
+ x: int = T(T.ID | T.RUNTIME)
8
+ v: int = T(T.ID | T.RUNTIME)
9
+
10
+ def v_get(self):
11
+ return self.x + 1
12
+
13
+
14
+ class Y(X):
15
+ v: int = M(flags=(None, T.ID), default=3)
16
+
17
+
18
+ class Z(Y):
19
+ v: float = M(default=XNone)
20
+
21
+ def v_get(self):
22
+ return self.x + 3
23
+
24
+
25
+ if __name__ == '__main__':
26
+ x = X(x=1)
27
+ y = Y(x=1)
28
+ z = Z(x=1)
29
+ print(x, x.v)
30
+ print(y, y.v)
31
+ print(z, z.v)
32
+
33
+ print(getattr(x, '__dict__', 'n/a'))
34
+ print(getattr(y, '__dict__', 'n/a'))
35
+ print(getattr(z, '__dict__', 'n/a'))
36
+
37
+
38
+ # NOTES:
39
+ # current classes trait.get override base classes trait_get
40
+ # current classes trait_get, overrides base classes trait.get, except if there is a trait modification in this class, in which case, it needs to reset trait.get
41
+ # en error is thrown if trait_get and trait.get are defined in the same class (or there is a trait modification that does nto reset trait.get)
42
+ # TODO: should trait.default should work just as trait.get?
@@ -0,0 +1,26 @@
1
+ from core_10x.traitable import RT, M, Traitable
2
+
3
+
4
+ class A(Traitable):
5
+ funny_message: str = RT()
6
+
7
+ def funny_message_get(self):
8
+ dt = self.T.funny_message.data_type
9
+ return f'{dt}'
10
+
11
+ class B(A):
12
+ funny_message:int = M()
13
+
14
+ class C(A):
15
+ funny_message:float = M()
16
+
17
+ def funny_message_get(self):
18
+ dt = self.T.funny_message.data_type
19
+ return f'{dt}'
20
+
21
+ if __name__ == '__main__':
22
+ a = A()
23
+ b = B()
24
+ c = C()
25
+
26
+ print(f'A: {a.funny_message}; B: {b.funny_message}; C: {c.funny_message}')
@@ -0,0 +1,82 @@
1
+ from __future__ import annotations
2
+
3
+ from datetime import date, datetime
4
+
5
+ import pytest
6
+ from infra_10x.mongodb_store import MongoStore
7
+ from typing_extensions import Self
8
+
9
+ from core_10x.code_samples.person import Person
10
+ from core_10x.exec_control import BTP, CACHE_ONLY, GRAPH_OFF, GRAPH_ON, INTERACTIVE
11
+ from core_10x.rc import RC, RC_TRUE
12
+ from core_10x.traitable import AsOfContext, T
13
+
14
+
15
+ class MarriedPerson(Person):
16
+ spouse: Self = T()
17
+
18
+ def spouse_set(self, trait, spouse) -> RC:
19
+ self.raw_set_value(trait, spouse)
20
+ if spouse:
21
+ spouse.raw_set_value(trait, self)
22
+ return RC_TRUE
23
+
24
+
25
+ if __name__ == '__main__':
26
+ with MongoStore.instance(hostname='localhost', dbname='traitable_history_test'):
27
+ MarriedPerson.delete_collection()
28
+ MarriedPerson.s_history_class.delete_collection()
29
+
30
+ with BTP.create_root():
31
+ # Create and save a person
32
+ person = MarriedPerson(first_name='Alyssa', last_name='Lees', dob=date(1985, 7, 5), _replace=True)
33
+ person.spouse = MarriedPerson(first_name='James', last_name='Bond', dob=date(1985, 7, 5), _replace=True)
34
+ person.spouse.save()
35
+ person.save()
36
+
37
+ ts = datetime.utcnow()
38
+
39
+ # Update and save again
40
+ person.dob = date(1985, 7, 6)
41
+ person.spouse.dob = date(1985, 7, 6)
42
+ person.save(save_references=True).throw()
43
+
44
+ person_id = person.id()
45
+ print(person.serialize_object())
46
+
47
+ with CACHE_ONLY():
48
+ assert not MarriedPerson.existing_instance_by_id(person_id, _throw=False)
49
+
50
+ for ctx in (
51
+ INTERACTIVE,
52
+ GRAPH_ON,
53
+ GRAPH_OFF,
54
+ ):
55
+ for as_of in (
56
+ ts,
57
+ None,
58
+ ):
59
+ with ctx():
60
+ person1 = MarriedPerson(person_id)
61
+ assert person1.dob == date(1985, 7, 6)
62
+
63
+ person_as_of = MarriedPerson.as_of(person_id, as_of_time=ts)
64
+
65
+ with AsOfContext([MarriedPerson], as_of_time=as_of):
66
+ with pytest.raises(RuntimeError, match=r'MarriedPerson/Alyssa|Lees: object not usable - origin cache is not reachable'):
67
+ _ = person1.dob
68
+
69
+ with pytest.raises(RuntimeError, match=r'MarriedPerson/Alyssa|Lees: object not usable - origin cache is not reachable'):
70
+ _ = person_as_of.dob
71
+
72
+ person2 = MarriedPerson(person_id)
73
+ assert person2.dob == (date(1985, 7, 5 + (as_of is None)))
74
+ assert person2.spouse.dob == (date(1985, 7, 5 + (as_of is None)))
75
+
76
+ assert person1.spouse.dob == date(1985, 7, 6)
77
+ assert person_as_of.dob == date(1985, 7, 5)
78
+
79
+ assert person_as_of.spouse.dob == date(1985, 7, 6) # note - since no AsOfContext was used, nested objects are not loaded "as_of".
80
+
81
+ with pytest.raises(RuntimeError, match=r'MarriedPerson/Alyssa|Lees: object not usable - origin cache is not reachable'):
82
+ _ = person2.dob
@@ -0,0 +1,39 @@
1
+ from core_10x.traitable_heir import TraitableHeir, T, RT
2
+
3
+ class Conventions(TraitableHeir):
4
+ mkt_name: str = T(T.ID)
5
+
6
+ days_to_settle: int = T()
7
+
8
+ c_dir = dict(Conventions.s_dir)
9
+
10
+ class XConventions(Conventions):
11
+ days_to_settle_twice: int = RT()
12
+
13
+ def days_to_settle_twice_get(self):
14
+ return 2*self.days_to_settle
15
+
16
+ c_dir2 = Conventions.s_dir
17
+
18
+ if __name__ == '__main__':
19
+ from core_10x.manual_tests.traitable_heir_test import Conventions, XConventions
20
+
21
+ mkt_name = 'WTI NYMEX'
22
+ c = Conventions(mkt_name = mkt_name)
23
+ c.days_to_settle = 2
24
+ print(c.days_to_settle)
25
+
26
+ loc = 'ICE'
27
+ mkt_name2 = f'{mkt_name} {loc}'
28
+ c2 = Conventions(mkt_name = mkt_name2)
29
+ c2._grantor = c
30
+
31
+ print(c2.days_to_settle)
32
+
33
+ c.days_to_settle = 3
34
+ print(c2.days_to_settle)
35
+
36
+ xc = XConventions(mkt_name = mkt_name)
37
+ xc._grantor = c
38
+
39
+ print(xc.days_to_settle_twice)
@@ -0,0 +1,41 @@
1
+ from datetime import date, datetime
2
+
3
+ from infra_10x.mongodb_store import MongoStore
4
+
5
+ from core_10x.code_samples.person import Person
6
+
7
+ if __name__ == '__main__':
8
+ with MongoStore.instance(hostname='localhost', dbname='traitable_history_test'):
9
+ Person.delete_collection()
10
+ Person.s_history_class.delete_collection()
11
+
12
+ # Create and save a person
13
+ person = Person(first_name='Alyssa', last_name='Lees', dob=date(1985, 7, 5), _replace=True)
14
+ person.save()
15
+
16
+ ts = datetime.utcnow()
17
+
18
+ # Update and save again
19
+ person.dob = date(1985, 7, 6)
20
+ person.save()
21
+
22
+ # Check history
23
+ history = Person.history()
24
+
25
+ # Verify server-side fields
26
+ for entry in history:
27
+ print(f' - Revision {entry["_traitable_rev"]}: {entry["first_name"]} (dob: {entry["dob"]})')
28
+ print(f' _who: {entry["_who"]}, _at: {entry["_at"]}')
29
+
30
+ assert person.dob == date(1985, 7, 6)
31
+
32
+ print(Person.restore(person.id(), timestamp=ts))
33
+ assert person.dob == date(1985, 7, 5)
34
+
35
+ person.reload()
36
+ assert person.dob == date(1985, 7, 6)
37
+
38
+ print(Person.restore(person.id(), timestamp=ts, save=True))
39
+ assert person.dob == date(1985, 7, 5)
40
+ person.reload()
41
+ assert person.dob == date(1985, 7, 5)
@@ -0,0 +1,54 @@
1
+ from datetime import date
2
+
3
+ from core_10x.named_constant import NamedConstant
4
+ from core_10x.traitable import THIS_CLASS, AnonymousTraitable, T, Traitable
5
+
6
+
7
+ class MARRITAL_STATUS(NamedConstant):
8
+ SINGLE = ()
9
+ MARRIED = ()
10
+ DIVORCED = ()
11
+ WIDOWED = ()
12
+
13
+ class Address(AnonymousTraitable):
14
+ street: str = T()
15
+ cszip: str = T()
16
+
17
+ class Person(Traitable):
18
+ ssn: str = T(T.ID)
19
+
20
+ dob: date = T()
21
+ name: str = T()
22
+ gender: bool = T()
23
+ marrital_status: MARRITAL_STATUS = T()
24
+
25
+ spouse: THIS_CLASS = T()
26
+ children: list = T()
27
+
28
+ address: Address = T(T.EMBEDDED)
29
+
30
+ if __name__ == '__main__':
31
+ address = Address(street="145 Austin Dr", cszip="Burlington, VT 05401")
32
+
33
+ woman = Person(ssn = '008-59-6666', name = 'Alice Smith', dob = date(1972, 8, 21), _replace = True)
34
+ daughter = Person(ssn = '008-77-7777', name = 'Ann Smith', dob = date(1997, 6, 17), _replace = True)
35
+ son = Person(ssn = '008-99-5555', name = 'Nathan Smith', dob = date(1999, 9, 23), _replace = True)
36
+
37
+
38
+ man = Person(_replace = True,
39
+ ssn = '009-87-4444',
40
+ name = 'John Smith',
41
+ gender = True,
42
+ dob = date(1965, 2, 3),
43
+ marrital_status = MARRITAL_STATUS.MARRIED,
44
+ spouse = woman,
45
+ children = [daughter, son],
46
+ address = address
47
+ )
48
+
49
+ ss = man.serialize_object()
50
+
51
+ man2 = Person.deserialize_object(Person.s_bclass, None, ss)
52
+
53
+ print(man == man2)
54
+
@@ -0,0 +1,71 @@
1
+ from datetime import date, datetime
2
+
3
+ from core_10x.code_samples.person import Person
4
+ from core_10x.traitable import T, Traitable, Trait, BTraitFlags
5
+
6
+
7
+ class Event(Traitable):
8
+ at: datetime = T()
9
+
10
+ class Dummy(Traitable):
11
+ name: str = T(T.ID)
12
+ payload: float = T(3.1415)
13
+
14
+ def name_get(self):
15
+ return 'AMD'
16
+
17
+ if __name__ == '__main__':
18
+ from core_10x.manual_tests.traitable_trivial_test import Dummy, Event
19
+
20
+ e = Event()
21
+ print(e.id_value())
22
+ rc = e.set_values(at = datetime.now())
23
+
24
+ p = Person(first_name = 'Sasha', last_name = 'Davidovich')
25
+ #print(p.id(), p.full_name)
26
+
27
+ # p.full_name = 'Ilya Pevzner'
28
+ # print(p.full_name)
29
+ # print(f'first name = {p.first_name}; last name = {p.last_name}')
30
+
31
+ p.dob = date(1963, 5, 14)
32
+ #p.age = 61
33
+
34
+ #print(f'older_than(25) = {p.older_than(25)}')
35
+
36
+ #try:
37
+ # p.older_than = False
38
+ #except TypeError as ex:
39
+ # print(ex)
40
+
41
+ #p.older_than = trait_value(False, 25) #-- set with args!
42
+ #print(f'older_than(25) = {p.older_than(25)}')
43
+
44
+ #print(p.from_any(p.T.older_than(), 'False'))
45
+
46
+ p2 = Person(first_name = 'Sasha', last_name = 'Davidovich')
47
+ #assert p2.age == 61
48
+ print(p2.age)
49
+
50
+ #print(Nucleus.serialize_any(p,False))
51
+
52
+ name = 'AMD'
53
+ d = Dummy()
54
+ assert d.name == name
55
+ d.payload = 100.
56
+
57
+ d2 = Dummy(name = name)
58
+ assert d2.name == d.name
59
+
60
+ dx = Dummy.existing_instance(name = name)
61
+ assert dx.payload == 100.
62
+
63
+ dx2 = Dummy.existing_instance()
64
+ assert dx2.payload == 100.
65
+
66
+ fn_t = Person.trait('first_name')
67
+ wqu_t = Person.trait('weight_qu')
68
+ w_t = Person.trait('weight')
69
+
70
+ print(f'first_name = {fn_t.has_custom_getter()}; weight_qu = {wqu_t.has_custom_getter()}; weight = {w_t.has_custom_getter()}')
71
+
@@ -0,0 +1,16 @@
1
+ from core_10x.exec_control import CACHE_ONLY
2
+
3
+ if __name__ == '__main__':
4
+ from core_10x.code_samples.person import Person
5
+ from core_10x.exec_control import GRAPH_ON
6
+
7
+ with (GRAPH_ON(convert_values = True, debug = True),CACHE_ONLY()):
8
+ p = Person(first_name = 'John', last_name = 'Smith')
9
+
10
+ print(p.full_name)
11
+ p.dob = '19630514'
12
+ p.weight_lbs = 170
13
+
14
+ ser = p.serialize_object()
15
+
16
+ print(p,ser)
@@ -0,0 +1,64 @@
1
+ from core_10x.code_samples.person import Person
2
+ from core_10x.traitable import NamedTsStore, T, Traitable, TsClassAssociation, TsStore
3
+
4
+
5
+ class Dummy1(Traitable):
6
+ text: str = T(T.ID)
7
+
8
+ class Dummy2(Traitable):
9
+ text: str = T(T.ID)
10
+
11
+ class Dummy3(Dummy2):
12
+ ...
13
+
14
+ if __name__ == '__main__':
15
+ from core_10x.environment_variables import EnvVars
16
+ from core_10x.manual_tests.ts_class_association_test import Dummy1, Dummy2, Dummy3
17
+ from core_10x.py_class import PyClass
18
+
19
+ #-- 0) Create a Person instance and save - must go to the main TsStore - no association
20
+ p = Person(first_name = 'A', last_name = 'B')
21
+ p.save().throw()
22
+ db = TsStore.instance_from_uri(EnvVars.main_ts_store_uri)
23
+ with db:
24
+ assert Person.exists_in_store(p.id()), f'Person must have been stored to {EnvVars.main_ts_store_uri}'
25
+
26
+ #-- 1) Create NamedTsStore objects referring to all available extra TsStores for Class Associations
27
+ extra_uris = dict(
28
+ dummy1 = 'mongodb://localhost/dummy1',
29
+ dummy2 = 'mongodb://localhost/dummy2',
30
+ )
31
+ for name, uri in extra_uris.items():
32
+ #store = TsStore.instance_from_uri(uri)
33
+ ns = NamedTsStore(_replace = True,
34
+ logical_name = name,
35
+ uri = uri,
36
+ )
37
+ ns.save().throw()
38
+
39
+ #-- 2) Create Class Association for Dummy1 - explicit association for the class
40
+ TsClassAssociation(_replace = True,
41
+ py_canonical_name = PyClass.name(Dummy1),
42
+ ts_logical_name = 'dummy1',
43
+ ).save().throw()
44
+
45
+ #-- 3) Create Class Association for Dummy2 - explicit association for the class
46
+ TsClassAssociation(_replace = True,
47
+ py_canonical_name = PyClass.name(Dummy2),
48
+ ts_logical_name = 'dummy2',
49
+ ).save().throw()
50
+
51
+ #-- 4) Create an instance of Dummy1 and save it - must go to dummy1 TsStore
52
+ d1 = Dummy1(text = 'hello dummy1')
53
+ d1.save().throw()
54
+ db1 = TsStore.instance_from_uri(extra_uris['dummy1'])
55
+ with db1:
56
+ assert Dummy1.exists_in_store(d1.id()), f'Dummy1 must have been associated with {extra_uris["dummy1"]}'
57
+
58
+ #-- 5) Create an instance of Dummy3 and save it - must go to dummy2 TsStore because it deriuves from Dummy2 which is associated with dummy2 TsStore
59
+ d3 = Dummy3(text = 'hello dummy3')
60
+ d3.save().throw()
61
+ db2 = TsStore.instance_from_uri(extra_uris['dummy2'])
62
+ with db2:
63
+ assert Dummy3.exists_in_store(d3.id()), f'Dummy3 must have been associated with {extra_uris["dummy2"]}'
64
+
@@ -0,0 +1,35 @@
1
+ if __name__ == '__main__':
2
+ from core_10x.code_samples.person import Person
3
+
4
+ to_save = True
5
+
6
+
7
+ #print(db.collection_names())
8
+
9
+ #Person.collection().delete('Sasha|Davidovich')
10
+ if to_save:
11
+ p = Person(first_name = 'Sasha', last_name = 'Davidovich')
12
+ p.weight_lbs=200
13
+ rev = p.save()
14
+
15
+ else:
16
+ p = Person(first_name = 'Sasha', last_name = 'Davidovich')
17
+ p.weight_lbs=200
18
+
19
+ print(p.age)
20
+
21
+ p.age = 61
22
+ rev = p.save()
23
+ print(p.age)
24
+
25
+ p.age = -10
26
+ print(p.age)
27
+
28
+ p.reload()
29
+ print(p.age)
30
+
31
+
32
+
33
+
34
+
35
+