14
0

Accepting request 767696 from home:mnhauke:branches:home:ojkastl_buildservice:Redfish_openSUSE

Initial package for python-formats

OBS-URL: https://build.opensuse.org/request/show/767696
OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-formats?expand=0&rev=1
This commit is contained in:
Tomáš Chvátal
2020-01-28 08:10:08 +00:00
committed by Git OBS Bridge
commit 7737c504e1
7 changed files with 1180 additions and 0 deletions

30
test_formats.py Normal file
View File

@@ -0,0 +1,30 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
from formats import FormatBank
class TestFormats(unittest.TestCase):
def test_discovery(self):
formats = FormatBank()
formats.discover()
def test_registering(self):
formats = FormatBank()
formats.discover_json()
def composer(text):
return '1:%s' % text
def parser(text):
return text[2:]
formats.register('test', parser, composer)
assert formats.parse('test', '1:hello') == 'hello'
assert formats.compose('test', 'hello') == '1:hello'
assert formats.convert('test', 'json', '1:hello') == '"hello"'
assert formats.convert('test', 'test', '1:hello') == '1:hello'
if __name__ == '__main__':
unittest.main()