test_yaml.py 19 KB

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