test_yaml.py 19 KB

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