test_yaml.py 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  1. # -*- coding: utf-8 -*-
  2. import pytest
  3. import datetime
  4. import difflib
  5. import finoex
  6. import ioex.calcex
  7. import ioex.datetimeex
  8. import os
  9. import pytz
  10. yaml = pytest.importorskip('yaml')
  11. def get_figure_a():
  12. return ioex.calcex.Figure(12.3, u'km')
  13. def get_figure_b():
  14. return ioex.calcex.Figure(12300, u'米')
  15. def get_sum_a():
  16. return finoex.Sum(1.23, u'EUR')
  17. def get_sum_b():
  18. return finoex.Sum(20.45, u'€')
  19. def get_item_a(sub_items = False):
  20. item = finoex.Item(
  21. name = u'item a',
  22. price_brutto = get_sum_a(),
  23. )
  24. if sub_items:
  25. item.sub_items.append(get_item_b())
  26. return item
  27. def get_item_b():
  28. return finoex.Item(
  29. name = u'item β',
  30. price_brutto = get_sum_b(),
  31. )
  32. def get_service_a():
  33. return finoex.Service(
  34. duration = ioex.datetimeex.Duration(years = 2),
  35. ip_addresses = ['::1'],
  36. location = 'vienna',
  37. name = u'service',
  38. price_brutto = finoex.Sum(1.0, u'EUR'),
  39. state = 'success',
  40. )
  41. def get_hosting_service():
  42. return finoex.HostingService(
  43. duration = ioex.datetimeex.Duration(years = 2),
  44. ip_addresses = ['127.0.0.1', '::1'],
  45. location = 'vienna',
  46. name = u'virtual server',
  47. operating_system = 'debian 8',
  48. price_brutto = finoex.Sum(1.0, u'EUR'),
  49. state = 'running',
  50. )
  51. def get_cloud_mining():
  52. return finoex.CloudMining(
  53. hashrate = ioex.calcex.Figure(8, u'TH/s'),
  54. name = u'sha256 BTC',
  55. price_brutto = finoex.Sum(1.0, u'EUR'),
  56. )
  57. def get_service_b():
  58. return finoex.Service(
  59. name = u'service',
  60. price_brutto = finoex.Sum(1.0, u'EUR'),
  61. period = ioex.datetimeex.Period(
  62. start = datetime.datetime(2017, 4, 2, 10, 23),
  63. end = None,
  64. ),
  65. )
  66. def get_person_a():
  67. return finoex.Person(
  68. first_name = u'Fabian Peter',
  69. last_name = u'Hammerle',
  70. )
  71. def get_person_b():
  72. return finoex.Person(
  73. first_name = u'名字',
  74. last_name = u'贵姓',
  75. )
  76. def get_campaign_a():
  77. return finoex.Campaign(
  78. name = u'campaign a',
  79. founder = u'company',
  80. end = datetime.datetime(2016, 7, 23, 9, 23, 17, tzinfo = pytz.timezone('Europe/Vienna')),
  81. )
  82. def get_campaign_b():
  83. return finoex.Campaign(
  84. founder = u'company',
  85. name = u'campaign without end',
  86. website_url = u'http://campaign.com',
  87. )
  88. def get_pledge():
  89. return finoex.Pledge(
  90. campaign = get_campaign_a(),
  91. price_brutto = finoex.Sum(10.0, u'EUR'),
  92. reward = u'great',
  93. )
  94. def get_contribution():
  95. return finoex.Contribution(
  96. campaign = get_campaign_a(),
  97. price_brutto = finoex.Sum(10.0, u'EUR'),
  98. reward = u'product',
  99. )
  100. def get_article():
  101. return finoex.Article(
  102. authors = ['a', 'b'],
  103. depth = finoex.Distance(12.3, u'dm'),
  104. features = u'supergeil',
  105. height = finoex.Distance(123., u'cm'),
  106. maximum_load = ioex.calcex.Figure(40., u'kg'),
  107. name = u'article name',
  108. price_brutto = get_sum_a(),
  109. product_id = u'0815',
  110. quantity = 1,
  111. reseller = u'seller',
  112. shipper = u'shipper',
  113. state = u'goood',
  114. width = finoex.Distance(1.23, u'm'),
  115. )
  116. def get_transportation(period=False):
  117. arrival_time = pytz.timezone('Europe/Vienna').localize(
  118. datetime.datetime(2016, 7, 24, 23, 47, 35)
  119. )
  120. if period:
  121. arrival_time = ioex.datetimeex.Period(
  122. start=arrival_time,
  123. end=arrival_time + datetime.timedelta(days=2),
  124. )
  125. return finoex.Transportation(
  126. name = u'ticket',
  127. price_brutto = get_sum_a(),
  128. departure_point = u'home',
  129. destination_point = u'city',
  130. distance = finoex.Distance(3.21, u'km'),
  131. passenger = get_person_a(),
  132. valid_from = datetime.datetime(2016, 7, 14, 13, 50, 4, 0, tzinfo = pytz.timezone('Europe/Vienna')),
  133. valid_until = datetime.datetime(2016, 7, 14, 18, 50, 4, 0, tzinfo = pytz.utc),
  134. ticket_url = u'https://www.example.com',
  135. estimated_arrival_time = ioex.datetimeex.Period(
  136. start = pytz.timezone('Europe/Vienna').localize(datetime.datetime(2016, 7, 24, 23, 47, 2)),
  137. end = pytz.utc.localize(datetime.datetime(2016, 7, 24, 23, 48, 5)),
  138. ),
  139. arrival_time=arrival_time,
  140. )
  141. def get_shipping():
  142. return finoex.Shipping(
  143. price_brutto = get_sum_a(),
  144. destination_point = u'home',
  145. tracking_number = 'LX123456789CN',
  146. )
  147. def get_taxi_ride():
  148. return finoex.TaxiRide(
  149. name = u'taxi ride',
  150. price_brutto = get_sum_a(),
  151. departure_point = u'home',
  152. destination_point = u'city',
  153. distance = finoex.Distance(3.21, u'km'),
  154. driver = u'driver',
  155. arrival_time = datetime.datetime(2016, 5, 2, 18, 10, tzinfo = pytz.timezone('Europe/Vienna')),
  156. departure_time = datetime.datetime(2016, 5, 2, 18, 25, tzinfo = pytz.timezone('Europe/Vienna')),
  157. )
  158. def get_discount_a():
  159. return finoex.Discount(
  160. name = u'discount a',
  161. amount = get_sum_a(),
  162. )
  163. def get_discount_b():
  164. return finoex.Discount(
  165. name = u'discount β',
  166. amount = get_sum_b(),
  167. )
  168. def get_discount_c():
  169. return finoex.Discount(
  170. amount = get_sum_b(),
  171. code = 'DISCΓ',
  172. name = u'discount c',
  173. )
  174. def get_order_a(items = True, discounts = True):
  175. order = finoex.Order(
  176. platform = u'platformπ',
  177. order_id = u'id',
  178. order_date = datetime.datetime(2016, 5, 8, 0, 18, 17),
  179. customer_id = u'customer',
  180. )
  181. if items:
  182. order.items.append(get_item_a())
  183. order.items.append(get_item_b())
  184. if discounts:
  185. order.discounts.append(get_discount_a())
  186. order.discounts.append(get_discount_b())
  187. return order
  188. def get_order_b():
  189. order = finoex.Order(
  190. platform = u'platformπ',
  191. order_id = u'order_b',
  192. order_date = datetime.datetime(2015, 5, 8, 0, 18, 17),
  193. )
  194. return order
  195. def get_order_c():
  196. order = finoex.Order(
  197. platform = u'γάμμα',
  198. order_id = u'order_βήτα',
  199. order_date = datetime.datetime(2014, 5, 8, 0, 18, 17),
  200. customer_id = u'ρώ',
  201. )
  202. return order
  203. def get_invoice(items = True, discounts = True):
  204. inv = finoex.Invoice(
  205. creditor = u'platformπ',
  206. invoice_id = u'id',
  207. invoice_date = datetime.datetime(2016, 5, 8, 0, 18, 17),
  208. debitor_id = u'customer',
  209. )
  210. if items:
  211. inv.items.append(get_item_a())
  212. inv.items.append(get_item_b())
  213. if discounts:
  214. inv.discounts.append(get_discount_a())
  215. return inv
  216. def get_distance():
  217. return finoex.Distance(2.4142, u'km')
  218. def to_yaml(data):
  219. class Dumper(yaml.Dumper):
  220. pass
  221. ioex.datetimeex.Duration.register_yaml_representer(yaml.Dumper)
  222. ioex.datetimeex.Period.register_yaml_representer(yaml.Dumper)
  223. ioex.calcex.Figure.register_yaml_representer(yaml.Dumper)
  224. finoex.Sum.register_yaml_representer(yaml.Dumper)
  225. finoex.Distance.register_yaml_representer(yaml.Dumper)
  226. return yaml.dump(
  227. data,
  228. default_flow_style = False,
  229. allow_unicode = True,
  230. Dumper = Dumper,
  231. ) #.decode('utf-8')
  232. def yaml_diff(a, b):
  233. return '\n'.join(difflib.ndiff(
  234. to_yaml(a).split('\n'),
  235. to_yaml(b).split('\n'),
  236. ))
  237. @pytest.mark.parametrize('source_object,expected_yaml', [
  238. [datetime.datetime(2016, 7, 14, 13, 50, 4, 0), '2016-07-14 13:50:04\n...\n'],
  239. [datetime.datetime(2016, 7, 14, 13, 50, 4, 0, tzinfo = pytz.timezone('Europe/Vienna')), '2016-07-14 13:50:04+01:05\n...\n'],
  240. [datetime.datetime(2016, 7, 14, 13, 50, 4, 0, tzinfo = pytz.utc), '2016-07-14 13:50:04+00:00\n...\n'],
  241. [finoex.Distance(1.34, u'km'), u"!distance '1.34 km'\n"],
  242. [finoex.Distance(1.34, u'μm'), u"!distance '1.34 μm'\n"],
  243. [get_discount_a(), u"!discount\namount: !sum '1.23 EUR'\nname: discount a\n"],
  244. [get_discount_b(), u"!discount\namount: !sum '20.45 EUR'\nname: discount β\n"],
  245. [get_discount_c(), u"""!discount
  246. amount: !sum '20.45 EUR'
  247. code: DISCΓ
  248. name: discount c
  249. """],
  250. [get_figure_a(), u"!figure '12.3 km'\n"],
  251. [get_figure_b(), u"!figure '12300 米'\n"],
  252. [get_item_a(), u"!item\nname: item a\nprice_brutto: !sum '1.23 EUR'\n"],
  253. [get_item_a(sub_items=True), u"""!item
  254. name: item a
  255. price_brutto: !sum '1.23 EUR'
  256. sub_items:
  257. - !item
  258. name: item β
  259. price_brutto: !sum '20.45 EUR'
  260. """],
  261. [get_item_b(), u"!item\nname: item β\nprice_brutto: !sum '20.45 EUR'\n"],
  262. [get_person_a(), u'!person\nfirst_name: Fabian Peter\nlast_name: Hammerle\n'],
  263. [get_person_b(), u'!person\nfirst_name: 名字\nlast_name: 贵姓\n'],
  264. [get_campaign_a(), u"""!campaign
  265. end: 2016-07-23 09:23:17+01:05
  266. founder: company
  267. name: campaign a
  268. """],
  269. [get_campaign_b(), u"""!campaign
  270. founder: company
  271. name: campaign without end
  272. website_url: http://campaign.com
  273. """],
  274. [get_service_a(), u"""!service
  275. duration: !duration
  276. years: 2
  277. ip_addresses:
  278. - ::1
  279. location: vienna
  280. name: service
  281. price_brutto: !sum '1.0 EUR'
  282. state: success
  283. """],
  284. [get_service_b(), u"""!service
  285. name: service
  286. period: !period
  287. end: null
  288. start: 2017-04-02 10:23:00
  289. price_brutto: !sum '1.0 EUR'
  290. """],
  291. [get_hosting_service(), u"""!hosting-service
  292. duration: !duration
  293. years: 2
  294. ip_addresses:
  295. - 127.0.0.1
  296. - ::1
  297. location: vienna
  298. name: virtual server
  299. operating_system: debian 8
  300. price_brutto: !sum '1.0 EUR'
  301. state: running
  302. """],
  303. [get_cloud_mining(), u"""!cloud-mining
  304. hashrate: !figure '8 TH/s'
  305. name: sha256 BTC
  306. price_brutto: !sum '1.0 EUR'
  307. """],
  308. [get_pledge(), u"""!pledge
  309. campaign: !campaign
  310. end: 2016-07-23 09:23:17+01:05
  311. founder: company
  312. name: campaign a
  313. price_brutto: !sum '10.0 EUR'
  314. reward: great
  315. """],
  316. [get_contribution(), u"""!contribution
  317. campaign: !campaign
  318. end: 2016-07-23 09:23:17+01:05
  319. founder: company
  320. name: campaign a
  321. price_brutto: !sum '10.0 EUR'
  322. reward: product
  323. """],
  324. [get_order_a(), u"""!order
  325. customer_id: customer
  326. discounts:
  327. - !discount
  328. amount: !sum '1.23 EUR'
  329. name: discount a
  330. - !discount
  331. amount: !sum '20.45 EUR'
  332. name: discount β
  333. items:
  334. - !item
  335. name: item a
  336. price_brutto: !sum '1.23 EUR'
  337. - !item
  338. name: item β
  339. price_brutto: !sum '20.45 EUR'
  340. order_date: 2016-05-08 00:18:17
  341. order_id: id
  342. platform: platformπ
  343. """],
  344. [get_order_a(discounts = False), u"""!order
  345. customer_id: customer
  346. items:
  347. - !item
  348. name: item a
  349. price_brutto: !sum '1.23 EUR'
  350. - !item
  351. name: item β
  352. price_brutto: !sum '20.45 EUR'
  353. order_date: 2016-05-08 00:18:17
  354. order_id: id
  355. platform: platformπ
  356. """],
  357. [get_article(), u"""!article
  358. authors:
  359. - a
  360. - b
  361. depth: !distance '12.3 dm'
  362. features: supergeil
  363. height: !distance '123.0 cm'
  364. maximum_load: !figure '40.0 kg'
  365. name: article name
  366. price_brutto: !sum '1.23 EUR'
  367. product_id: 0815
  368. quantity: 1
  369. reseller: seller
  370. shipper: shipper
  371. state: goood
  372. width: !distance '1.23 m'
  373. """],
  374. [get_transportation(period=False), u"""!transportation
  375. arrival_time: 2016-07-24 23:47:35+02:00
  376. departure_point: home
  377. destination_point: city
  378. distance: !distance '3.21 km'
  379. estimated_arrival_time: !period
  380. end: 2016-07-24 23:48:05+00:00
  381. start: 2016-07-24 23:47:02+02:00
  382. name: ticket
  383. passenger: !person
  384. first_name: Fabian Peter
  385. last_name: Hammerle
  386. price_brutto: !sum '1.23 EUR'
  387. ticket_url: https://www.example.com
  388. valid_from: 2016-07-14 13:50:04+01:05
  389. valid_until: 2016-07-14 18:50:04+00:00
  390. """],
  391. [get_transportation(period=True), u"""!transportation
  392. arrival_time: !period
  393. end: 2016-07-26 23:47:35+02:00
  394. start: 2016-07-24 23:47:35+02:00
  395. departure_point: home
  396. destination_point: city
  397. distance: !distance '3.21 km'
  398. estimated_arrival_time: !period
  399. end: 2016-07-24 23:48:05+00:00
  400. start: 2016-07-24 23:47:02+02:00
  401. name: ticket
  402. passenger: !person
  403. first_name: Fabian Peter
  404. last_name: Hammerle
  405. price_brutto: !sum '1.23 EUR'
  406. ticket_url: https://www.example.com
  407. valid_from: 2016-07-14 13:50:04+01:05
  408. valid_until: 2016-07-14 18:50:04+00:00
  409. """],
  410. [get_shipping(), u"""!shipping
  411. destination_point: home
  412. price_brutto: !sum '1.23 EUR'
  413. tracking_number: LX123456789CN
  414. """],
  415. [get_taxi_ride(), u"""!taxi-ride
  416. arrival_time: 2016-05-02 18:10:00+01:05
  417. departure_point: home
  418. departure_time: 2016-05-02 18:25:00+01:05
  419. destination_point: city
  420. distance: !distance '3.21 km'
  421. driver: driver
  422. name: taxi ride
  423. price_brutto: !sum '1.23 EUR'
  424. """],
  425. [get_invoice(), u"""!invoice
  426. creditor: platformπ
  427. debitor_id: customer
  428. discounts:
  429. - !discount
  430. amount: !sum '1.23 EUR'
  431. name: discount a
  432. invoice_date: 2016-05-08 00:18:17
  433. invoice_id: id
  434. items:
  435. - !item
  436. name: item a
  437. price_brutto: !sum '1.23 EUR'
  438. - !item
  439. name: item β
  440. price_brutto: !sum '20.45 EUR'
  441. """],
  442. ])
  443. def test_to_yaml(source_object, expected_yaml):
  444. assert expected_yaml == to_yaml(source_object)
  445. @pytest.mark.parametrize('expected_object,source_yaml', [
  446. [datetime.datetime(2016, 7, 14, 13, 50, 4, 0), '2016-07-14 13:50:04'],
  447. [datetime.datetime(2016, 7, 14, 13, 50, 4, 0, tzinfo = pytz.timezone('Europe/Vienna')), '2016-07-14 13:50:04+01:05'],
  448. [datetime.datetime(2016, 7, 14, 13, 50, 4, 0, tzinfo = pytz.utc), '2016-07-14 13:50:04+00:00'],
  449. [finoex.Distance(1.34, u'km'), u"!distance '1.34 km'\n"],
  450. [finoex.Distance(1.34, u'μm'), u"!distance '1.34 μm'"],
  451. [get_discount_a(), u"!discount\nname: discount a\namount: !sum '1.23 EUR'\n"],
  452. [get_discount_b(), u"!discount\nname: discount β\namount: !sum '20.45 EUR'\n"],
  453. [get_discount_c(), u"""!discount
  454. amount: !sum 20.45 EUR
  455. name: discount c
  456. code: DISCΓ
  457. """],
  458. [get_figure_a(), '!figure\nunit: km\nvalue: 12.3\n'],
  459. [get_figure_a(), u'!figure\nunit: km\nvalue: 12.3\n'],
  460. [get_figure_b(), '!figure\nunit: 米\nvalue: 12300\n'],
  461. [get_figure_b(), u'!figure\nunit: 米\nvalue: 12300\n'],
  462. [get_item_a(), u"!item\nname: item a\nprice_brutto: !sum '1.23 EUR'\n"],
  463. [get_item_a(), u"!item\nname: item a\nprice_brutto: !sum 1.23 EUR"],
  464. [get_item_a(sub_items=True), u"""!item
  465. name: item a
  466. price_brutto: !sum '1.23 EUR'
  467. sub_items:
  468. - !item
  469. name: item β
  470. price_brutto: !sum '20.45 EUR'
  471. """],
  472. [get_item_a(), u"!item\nname: item a\nprice_brutto: !sum 1.23 €\n"],
  473. [get_item_b(), u"!item\nname: item β\nprice_brutto: !sum '20.45 EUR'\n"],
  474. [get_person_a(), '!person\nfirst_name: Fabian Peter\nlast_name: Hammerle\n'],
  475. [get_person_a(), u'!person\nfirst_name: Fabian Peter\nlast_name: Hammerle\n'],
  476. [get_person_b(), u'!person\nfirst_name: 名字\nlast_name: 贵姓\n'],
  477. [get_campaign_a(), u"""!campaign
  478. name: campaign a
  479. founder: company
  480. end: 2016-07-23 09:23:17+01:05
  481. """],
  482. [get_campaign_b(), u"""!campaign
  483. founder: company
  484. name: campaign without end
  485. website_url: http://campaign.com
  486. """],
  487. [get_service_a(), u"""!service
  488. duration: !duration
  489. years: 2
  490. ip_addresses:
  491. - ::1
  492. location: vienna
  493. name: service
  494. price_brutto: !sum '1.0 EUR'
  495. state: success
  496. """],
  497. [get_service_b(), u"""!service
  498. name: service
  499. period: !period
  500. start: 2017-04-02 10:23:00
  501. price_brutto: !sum '1.0 EUR'
  502. """],
  503. [get_hosting_service(), u"""!hosting-service
  504. duration: !duration
  505. years: 2
  506. ip_addresses:
  507. - 127.0.0.1
  508. - ::1
  509. location: vienna
  510. name: virtual server
  511. operating_system: debian 8
  512. price_brutto: !sum '1.0 EUR'
  513. state: running
  514. """],
  515. [get_cloud_mining(), u"""!cloud-mining
  516. hashrate: !figure 8 TH/s
  517. name: sha256 BTC
  518. price_brutto: !sum 1.0 EUR
  519. """],
  520. [get_pledge(), u"""!pledge
  521. campaign: !campaign
  522. name: campaign a
  523. founder: company
  524. end: 2016-07-23 09:23:17+01:05
  525. price_brutto: !sum '10.0 EUR'
  526. reward: great
  527. """],
  528. [get_contribution(), u"""!contribution
  529. campaign: !campaign
  530. end: 2016-07-23 09:23:17+01:05
  531. founder: company
  532. name: campaign a
  533. price_brutto: !sum '10.0 EUR'
  534. reward: product
  535. """],
  536. [[get_person_a(), get_person_b()], u"""
  537. - !person
  538. first_name: Fabian Peter
  539. last_name: Hammerle
  540. - !person
  541. first_name: 名字
  542. last_name: 贵姓"""],
  543. [get_transportation(period=False), u"""!transportation
  544. arrival_time: 2016-07-24 23:47:35+02:00
  545. departure_point: home
  546. destination_point: city
  547. distance: !distance '3.21 km'
  548. name: ticket
  549. price_brutto: !sum '1.23 EUR'
  550. route_map: null
  551. passenger: !person
  552. first_name: Fabian Peter
  553. last_name: Hammerle
  554. ticket_url: https://www.example.com
  555. valid_from: 2016-07-14 13:50:04+01:05
  556. valid_until: 2016-07-14 18:50:04+00:00
  557. estimated_arrival_time: !period
  558. end: 2016-07-24T23:48:05+00:00
  559. start: 2016-07-24T23:47:02+02:00
  560. """],
  561. [get_transportation(period=True), u"""!transportation
  562. arrival_time: !period
  563. end: 2016-07-26 23:47:35+02:00
  564. start: 2016-07-24 23:47:35+02:00
  565. departure_point: home
  566. destination_point: city
  567. distance: !distance '3.21 km'
  568. estimated_arrival_time: !period
  569. end: 2016-07-24 23:48:05+00:00
  570. start: 2016-07-24 23:47:02+02:00
  571. name: ticket
  572. passenger: !person
  573. first_name: Fabian Peter
  574. last_name: Hammerle
  575. price_brutto: !sum '1.23 EUR'
  576. ticket_url: https://www.example.com
  577. valid_from: 2016-07-14 13:50:04+01:05
  578. valid_until: 2016-07-14 18:50:04+00:00
  579. """],
  580. [get_shipping(), u"""!shipping
  581. destination_point: home
  582. price_brutto: !sum 1.23 EUR
  583. tracking_number: LX123456789CN
  584. """],
  585. [get_order_a(), u"""!order
  586. customer_id: customer
  587. discounts:
  588. - !discount
  589. amount: !sum '1.23 EUR'
  590. name: discount a
  591. - !discount
  592. amount: !sum '20.45 EUR'
  593. name: discount β
  594. items:
  595. - !item
  596. name: item a
  597. price_brutto: !sum '1.23 EUR'
  598. - !item
  599. name: item β
  600. price_brutto: !sum '20.45 EUR'
  601. order_date: 2016-05-08 00:18:17
  602. order_id: id
  603. platform: platformπ
  604. """],
  605. [get_article(), u"""!article
  606. authors:
  607. - a
  608. - b
  609. delivery_date: null
  610. features: supergeil
  611. name: article name
  612. price_brutto: !sum '1.23 EUR'
  613. product_id: 0815
  614. quantity: 1
  615. reseller: seller
  616. shipper: shipper
  617. state: goood
  618. depth: !distance 12.3 dm
  619. height: !distance 123.0 cm
  620. maximum_load: !figure 40.0 kg
  621. width: !distance 1.23 m
  622. """],
  623. [get_taxi_ride(), u"""!taxi-ride
  624. arrival_time: 2016-05-02 18:10:00+01:05
  625. departure_point: home
  626. departure_time: 2016-05-02 18:25:00+01:05
  627. destination_point: city
  628. distance: !distance '3.21 km'
  629. driver: driver
  630. name: taxi ride
  631. price_brutto: !sum '1.23 EUR'
  632. route_map: null
  633. """],
  634. [get_invoice(), u"""!invoice
  635. creditor: platformπ
  636. debitor_id: customer
  637. invoice_date: 2016-05-08T00:18:17
  638. invoice_id: id
  639. items:
  640. - !item
  641. name: item a
  642. price_brutto: !sum '1.23 EUR'
  643. - !item
  644. name: item β
  645. price_brutto: !sum '20.45 EUR'
  646. discounts:
  647. - !discount
  648. name: discount a
  649. amount: !sum 1.23 EUR
  650. """],
  651. ])
  652. def test_from_yaml(expected_object, source_yaml):
  653. class Loader(yaml.Loader):
  654. pass
  655. ioex.datetimeex.Duration.register_yaml_constructor(Loader)
  656. ioex.datetimeex.Period.register_yaml_constructor(Loader)
  657. ioex.calcex.Figure.register_yaml_constructor(Loader)
  658. finoex.Sum.register_yaml_constructor(Loader)
  659. finoex.Distance.register_yaml_constructor(Loader)
  660. loaded_object = yaml.load(source_yaml, Loader=Loader)
  661. assert loaded_object == expected_object