anymarkup-0.8.1/0000755000076500000240000000000013516252746015375 5ustar slavek.kabrdastaff00000000000000anymarkup-0.8.1/LICENSE0000644000076500000240000000266713515572740016413 0ustar slavek.kabrdastaff00000000000000Copyright (c) 2015, Slavek Kabrda All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. anymarkup-0.8.1/MANIFEST.in0000644000076500000240000000013013515572740017123 0ustar slavek.kabrdastaff00000000000000include README.rst include LICENSE include requirements.txt recursive-include test *.py anymarkup-0.8.1/PKG-INFO0000644000076500000240000002244013516252746016474 0ustar slavek.kabrdastaff00000000000000Metadata-Version: 1.1 Name: anymarkup Version: 0.8.1 Summary: Parse/serialize any markup format Home-page: https://github.com/bkabrda/anymarkup Author: Slavek Kabrda Author-email: slavek.kabrda@gmail.com License: BSD Description: anymarkup ========= .. image:: https://travis-ci.org/bkabrda/anymarkup.svg?branch=master :target: https://travis-ci.org/bkabrda/anymarkup :alt: Build Status .. image:: https://landscape.io/github/bkabrda/anymarkup/master/landscape.svg?style=flat :target: https://landscape.io/github/bkabrda/anymarkup/master :alt: Code Health .. image:: https://coveralls.io/repos/bkabrda/anymarkup/badge.svg?branch=master :target: https://coveralls.io/r/bkabrda/anymarkup?branch=master :alt: Coverage Parse or serialize any markup. Currently supports ini, json, json5, toml, xml and yaml. Report bugs and new functionality requests at https://github.com/bkabrda/anymarkup/issues. Parsing:: >>> import anymarkup >>> anymarkup.parse('foo: bar') {'foo': 'bar'} >>> anymarkup.parse_file('foo/bar.ini') {'section': {'subsection': {'opt2': 'bar'}, 'opt1': 'foo'}} $ cat foo/bar.ini [section] opt1=foo [[subsection]] opt2=bar Serializing:: >>> import anymarkup >>> anymarkup.serialize({'foo': 'bar'}, 'json') b'{\n "foo": "bar"\n}' >>> anymarkup.serialize_file({'foo': 'bar'}, 'foo/bar.json') $ cat foo/bar.json { "foo": "bar" } ``anymarkup`` is licensed under BSD license. You can download official releases from https://pypi.python.org/pypi/anymarkup or install them via ``pip install anymarkup``. ``anymarkup`` works with Python 2.7 and >= 3.3. Automatic Markup Language Recognition ------------------------------------- When using ``anymarkup.parse(input)``, anymarkup will try to guess markup language of input. This usually works fine except: * ini vs toml: These two look almost the same and in fact have common subset (which, however, yields different parsing result). Because of this, anything with an ini-like look will be parsed with ini parser. If you want an input string to be parsed as toml, you have to explicitly specify that using ``format=toml`` (see below for examples). * json vs json5: json5 is superset of json, but not very widely used. Because of practicality of json usage, everything that looks like json is parsed as json. If you want input string to be parsed as json5, you have to explicitly specify that using ``format=json5``. When using ``anymarkup.parse_file(path)``, anymarkup will try to guess format based on file extension and then fallback to guessing as explained above. This means that if the file has ``.toml`` pr ``.json5`` extension, you don't have to provide ``format=`` explicitly. Notes on Parsing Basic Types ---------------------------- When parsing, ``anymarkup`` recognizes basic types - ``NoneType``, ``int``, ``float`` and ``bool`` (and ``long`` on Python 2) and converts all values to these types. If you want to get everything as strings, just use ``force_types=False`` with ``parse`` or ``parse_file``. Finally, you can also use ``force_types=None`` to get whatever the parsing backend returned:: >>> anymarkup.parse('a: 1') {'a': 1} >>> anymarkup.parse('a: 1', force_types=False) {'a': '1'} >>> anymarkup.parse('a: 1', force_types=None) {'a': 1} CLI -------- To install the CLI, run the following command: pip install anymarkup Example of conversion from JSON to XML: anymarkup convert --from-format json --to-format xml bar """ yaml = """ a: foo: bar """ # these will all yield the same value (except that xml parsing will yield OrderedDict) anymarkup.parse(ini) anymarkup.parse(json) anymarkup.parse(xml) anymarkup.parse(yaml) # explicitly specify a type of format to expect and/or encoding (utf-8 is default) anymarkup.parse('foo: bar', format='yaml', encoding='ascii') # by default, anymarkup recognizes basic types (None, booleans, ints and floats) # if you want to get everything as strings, just use force_types=False # will yield {'a': 1, 'b': True, 'c': None} anymarkup.parse('a: 1\nb: True\nc: None') # will yield {'a': '1', 'b': 'True', 'c': 'None'} anymarkup.parse('a: 1\nb: True\nc: None', force_types=False) # or parse a file anymarkup.parse_file('foo.ini') # if a file doesn't have a format extension, pass it explicitly anymarkup.parse_file('foo', format='json') # you can also pass encoding explicitly (utf-8 is default) anymarkup.parse_file('bar', format='xml', encoding='ascii') Serializing examples:: struct = {'a': ['b', 'c']} for fmt in ['ini', 'json', 'xml', 'yaml']: # any of the above formats can be used for serializing anymarkup.serialize(struct, fmt) # explicitly specify encoding (utf-8 is default) anymarkup.serialize(struct, 'json', encoding='utf-8') # or serialize directly to a file anymarkup.serialize_file(struct, 'foo/bar.ini') # if a file doesn't have a format extension, pass it explicitly anymarkup.serialize_file(struct, 'foo/bar', format='json') # you can also pass encoding explicitly (utf-8 is default) anymarkup.serialize_file(struct, 'foo/bar', format='json', encoding='ascii') Keywords: xml,yaml,toml,json,json5,ini Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: POSIX :: Linux Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 anymarkup-0.8.1/README.rst0000644000076500000240000001565413515572740017075 0ustar slavek.kabrdastaff00000000000000anymarkup ========= .. image:: https://travis-ci.org/bkabrda/anymarkup.svg?branch=master :target: https://travis-ci.org/bkabrda/anymarkup :alt: Build Status .. image:: https://landscape.io/github/bkabrda/anymarkup/master/landscape.svg?style=flat :target: https://landscape.io/github/bkabrda/anymarkup/master :alt: Code Health .. image:: https://coveralls.io/repos/bkabrda/anymarkup/badge.svg?branch=master :target: https://coveralls.io/r/bkabrda/anymarkup?branch=master :alt: Coverage Parse or serialize any markup. Currently supports ini, json, json5, toml, xml and yaml. Report bugs and new functionality requests at https://github.com/bkabrda/anymarkup/issues. Parsing:: >>> import anymarkup >>> anymarkup.parse('foo: bar') {'foo': 'bar'} >>> anymarkup.parse_file('foo/bar.ini') {'section': {'subsection': {'opt2': 'bar'}, 'opt1': 'foo'}} $ cat foo/bar.ini [section] opt1=foo [[subsection]] opt2=bar Serializing:: >>> import anymarkup >>> anymarkup.serialize({'foo': 'bar'}, 'json') b'{\n "foo": "bar"\n}' >>> anymarkup.serialize_file({'foo': 'bar'}, 'foo/bar.json') $ cat foo/bar.json { "foo": "bar" } ``anymarkup`` is licensed under BSD license. You can download official releases from https://pypi.python.org/pypi/anymarkup or install them via ``pip install anymarkup``. ``anymarkup`` works with Python 2.7 and >= 3.3. Automatic Markup Language Recognition ------------------------------------- When using ``anymarkup.parse(input)``, anymarkup will try to guess markup language of input. This usually works fine except: * ini vs toml: These two look almost the same and in fact have common subset (which, however, yields different parsing result). Because of this, anything with an ini-like look will be parsed with ini parser. If you want an input string to be parsed as toml, you have to explicitly specify that using ``format=toml`` (see below for examples). * json vs json5: json5 is superset of json, but not very widely used. Because of practicality of json usage, everything that looks like json is parsed as json. If you want input string to be parsed as json5, you have to explicitly specify that using ``format=json5``. When using ``anymarkup.parse_file(path)``, anymarkup will try to guess format based on file extension and then fallback to guessing as explained above. This means that if the file has ``.toml`` pr ``.json5`` extension, you don't have to provide ``format=`` explicitly. Notes on Parsing Basic Types ---------------------------- When parsing, ``anymarkup`` recognizes basic types - ``NoneType``, ``int``, ``float`` and ``bool`` (and ``long`` on Python 2) and converts all values to these types. If you want to get everything as strings, just use ``force_types=False`` with ``parse`` or ``parse_file``. Finally, you can also use ``force_types=None`` to get whatever the parsing backend returned:: >>> anymarkup.parse('a: 1') {'a': 1} >>> anymarkup.parse('a: 1', force_types=False) {'a': '1'} >>> anymarkup.parse('a: 1', force_types=None) {'a': 1} CLI -------- To install the CLI, run the following command: pip install anymarkup Example of conversion from JSON to XML: anymarkup convert --from-format json --to-format xml bar """ yaml = """ a: foo: bar """ # these will all yield the same value (except that xml parsing will yield OrderedDict) anymarkup.parse(ini) anymarkup.parse(json) anymarkup.parse(xml) anymarkup.parse(yaml) # explicitly specify a type of format to expect and/or encoding (utf-8 is default) anymarkup.parse('foo: bar', format='yaml', encoding='ascii') # by default, anymarkup recognizes basic types (None, booleans, ints and floats) # if you want to get everything as strings, just use force_types=False # will yield {'a': 1, 'b': True, 'c': None} anymarkup.parse('a: 1\nb: True\nc: None') # will yield {'a': '1', 'b': 'True', 'c': 'None'} anymarkup.parse('a: 1\nb: True\nc: None', force_types=False) # or parse a file anymarkup.parse_file('foo.ini') # if a file doesn't have a format extension, pass it explicitly anymarkup.parse_file('foo', format='json') # you can also pass encoding explicitly (utf-8 is default) anymarkup.parse_file('bar', format='xml', encoding='ascii') Serializing examples:: struct = {'a': ['b', 'c']} for fmt in ['ini', 'json', 'xml', 'yaml']: # any of the above formats can be used for serializing anymarkup.serialize(struct, fmt) # explicitly specify encoding (utf-8 is default) anymarkup.serialize(struct, 'json', encoding='utf-8') # or serialize directly to a file anymarkup.serialize_file(struct, 'foo/bar.ini') # if a file doesn't have a format extension, pass it explicitly anymarkup.serialize_file(struct, 'foo/bar', format='json') # you can also pass encoding explicitly (utf-8 is default) anymarkup.serialize_file(struct, 'foo/bar', format='json', encoding='ascii') anymarkup-0.8.1/anymarkup/0000755000076500000240000000000013516252746017404 5ustar slavek.kabrdastaff00000000000000anymarkup-0.8.1/anymarkup/__init__.py0000644000076500000240000000020713516252603021504 0ustar slavek.kabrdastaff00000000000000# -*- coding: utf-8 -*- from anymarkup_core import AnyMarkupError, parse, parse_file, serialize, serialize_file __version__ = '0.8.1' anymarkup-0.8.1/anymarkup/cli.py0000644000076500000240000000274713516252564020535 0ustar slavek.kabrdastaff00000000000000# -*- coding: utf-8 -*- import anymarkup import sys import click @click.version_option(version=anymarkup.__version__, prog_name='anymarkup') @click.group() def cli(): """ anymarkup - Converts markup files from one format to another. Supports ini, json, json5, toml, xml and yaml. Source available at: https://github.com/bkabrda/anymarkup More help available by running: anymarkup convert --help """ @cli.command('convert') @click.argument('filename', type=click.File('r'), default='-') @click.option('-f', '--from-format', type=click.Choice(['ini', 'json', 'json5', 'toml', 'yaml', 'xml']), default=None, help='Input file format, if not specified, an educated guess will be made') @click.option('-t', '--to-format', type=click.Choice(['ini', 'json', 'json5', 'toml', 'yaml', 'xml']), default='json', help='Output format to serialize to, the default is JSON') @click.option('--interpolate/--no-interpolate', default=True, help='Whether to interpolate strings, the default is True') def convert(filename, from_format, to_format, interpolate): """Parses stdin or a file and converts to the specified format""" # Try to parse the file and output in the specified format data = anymarkup.parse(filename, format=from_format, interpolate=interpolate) serialized = anymarkup.serialize(data, format=to_format) click.echo(serialized) # Exit if all done sys.exit(0) if __name__ == '__main__': cli(prog_name='anymarkup')anymarkup-0.8.1/anymarkup.egg-info/0000755000076500000240000000000013516252746021076 5ustar slavek.kabrdastaff00000000000000anymarkup-0.8.1/anymarkup.egg-info/PKG-INFO0000644000076500000240000002244013516252745022174 0ustar slavek.kabrdastaff00000000000000Metadata-Version: 1.1 Name: anymarkup Version: 0.8.1 Summary: Parse/serialize any markup format Home-page: https://github.com/bkabrda/anymarkup Author: Slavek Kabrda Author-email: slavek.kabrda@gmail.com License: BSD Description: anymarkup ========= .. image:: https://travis-ci.org/bkabrda/anymarkup.svg?branch=master :target: https://travis-ci.org/bkabrda/anymarkup :alt: Build Status .. image:: https://landscape.io/github/bkabrda/anymarkup/master/landscape.svg?style=flat :target: https://landscape.io/github/bkabrda/anymarkup/master :alt: Code Health .. image:: https://coveralls.io/repos/bkabrda/anymarkup/badge.svg?branch=master :target: https://coveralls.io/r/bkabrda/anymarkup?branch=master :alt: Coverage Parse or serialize any markup. Currently supports ini, json, json5, toml, xml and yaml. Report bugs and new functionality requests at https://github.com/bkabrda/anymarkup/issues. Parsing:: >>> import anymarkup >>> anymarkup.parse('foo: bar') {'foo': 'bar'} >>> anymarkup.parse_file('foo/bar.ini') {'section': {'subsection': {'opt2': 'bar'}, 'opt1': 'foo'}} $ cat foo/bar.ini [section] opt1=foo [[subsection]] opt2=bar Serializing:: >>> import anymarkup >>> anymarkup.serialize({'foo': 'bar'}, 'json') b'{\n "foo": "bar"\n}' >>> anymarkup.serialize_file({'foo': 'bar'}, 'foo/bar.json') $ cat foo/bar.json { "foo": "bar" } ``anymarkup`` is licensed under BSD license. You can download official releases from https://pypi.python.org/pypi/anymarkup or install them via ``pip install anymarkup``. ``anymarkup`` works with Python 2.7 and >= 3.3. Automatic Markup Language Recognition ------------------------------------- When using ``anymarkup.parse(input)``, anymarkup will try to guess markup language of input. This usually works fine except: * ini vs toml: These two look almost the same and in fact have common subset (which, however, yields different parsing result). Because of this, anything with an ini-like look will be parsed with ini parser. If you want an input string to be parsed as toml, you have to explicitly specify that using ``format=toml`` (see below for examples). * json vs json5: json5 is superset of json, but not very widely used. Because of practicality of json usage, everything that looks like json is parsed as json. If you want input string to be parsed as json5, you have to explicitly specify that using ``format=json5``. When using ``anymarkup.parse_file(path)``, anymarkup will try to guess format based on file extension and then fallback to guessing as explained above. This means that if the file has ``.toml`` pr ``.json5`` extension, you don't have to provide ``format=`` explicitly. Notes on Parsing Basic Types ---------------------------- When parsing, ``anymarkup`` recognizes basic types - ``NoneType``, ``int``, ``float`` and ``bool`` (and ``long`` on Python 2) and converts all values to these types. If you want to get everything as strings, just use ``force_types=False`` with ``parse`` or ``parse_file``. Finally, you can also use ``force_types=None`` to get whatever the parsing backend returned:: >>> anymarkup.parse('a: 1') {'a': 1} >>> anymarkup.parse('a: 1', force_types=False) {'a': '1'} >>> anymarkup.parse('a: 1', force_types=None) {'a': 1} CLI -------- To install the CLI, run the following command: pip install anymarkup Example of conversion from JSON to XML: anymarkup convert --from-format json --to-format xml bar """ yaml = """ a: foo: bar """ # these will all yield the same value (except that xml parsing will yield OrderedDict) anymarkup.parse(ini) anymarkup.parse(json) anymarkup.parse(xml) anymarkup.parse(yaml) # explicitly specify a type of format to expect and/or encoding (utf-8 is default) anymarkup.parse('foo: bar', format='yaml', encoding='ascii') # by default, anymarkup recognizes basic types (None, booleans, ints and floats) # if you want to get everything as strings, just use force_types=False # will yield {'a': 1, 'b': True, 'c': None} anymarkup.parse('a: 1\nb: True\nc: None') # will yield {'a': '1', 'b': 'True', 'c': 'None'} anymarkup.parse('a: 1\nb: True\nc: None', force_types=False) # or parse a file anymarkup.parse_file('foo.ini') # if a file doesn't have a format extension, pass it explicitly anymarkup.parse_file('foo', format='json') # you can also pass encoding explicitly (utf-8 is default) anymarkup.parse_file('bar', format='xml', encoding='ascii') Serializing examples:: struct = {'a': ['b', 'c']} for fmt in ['ini', 'json', 'xml', 'yaml']: # any of the above formats can be used for serializing anymarkup.serialize(struct, fmt) # explicitly specify encoding (utf-8 is default) anymarkup.serialize(struct, 'json', encoding='utf-8') # or serialize directly to a file anymarkup.serialize_file(struct, 'foo/bar.ini') # if a file doesn't have a format extension, pass it explicitly anymarkup.serialize_file(struct, 'foo/bar', format='json') # you can also pass encoding explicitly (utf-8 is default) anymarkup.serialize_file(struct, 'foo/bar', format='json', encoding='ascii') Keywords: xml,yaml,toml,json,json5,ini Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Operating System :: POSIX :: Linux Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 2.7 Classifier: Programming Language :: Python :: 3.3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 anymarkup-0.8.1/anymarkup.egg-info/SOURCES.txt0000644000076500000240000000075613516252745022771 0ustar slavek.kabrdastaff00000000000000LICENSE MANIFEST.in README.rst requirements.txt setup.py anymarkup/__init__.py anymarkup/cli.py anymarkup.egg-info/PKG-INFO anymarkup.egg-info/SOURCES.txt anymarkup.egg-info/dependency_links.txt anymarkup.egg-info/entry_points.txt anymarkup.egg-info/requires.txt anymarkup.egg-info/top_level.txt test/__init__.py test/data.py test/test_cli.py test/test_cli_ini.py test/test_cli_json.py test/test_cli_json5.py test/test_cli_toml.py test/test_cli_xml.py test/test_cli_yaml.py test/test_imports.pyanymarkup-0.8.1/anymarkup.egg-info/dependency_links.txt0000644000076500000240000000000113516252745025143 0ustar slavek.kabrdastaff00000000000000 anymarkup-0.8.1/anymarkup.egg-info/entry_points.txt0000644000076500000240000000006113516252745024370 0ustar slavek.kabrdastaff00000000000000[console_scripts] anymarkup = anymarkup.cli:cli anymarkup-0.8.1/anymarkup.egg-info/requires.txt0000644000076500000240000000010713516252745023473 0ustar slavek.kabrdastaff00000000000000anymarkup-core>=0.8.0 click>=7.0 configobj json5 PyYAML toml xmltodict anymarkup-0.8.1/anymarkup.egg-info/top_level.txt0000644000076500000240000000001213516252745023620 0ustar slavek.kabrdastaff00000000000000anymarkup anymarkup-0.8.1/requirements.txt0000644000076500000240000000010713516252564020655 0ustar slavek.kabrdastaff00000000000000anymarkup-core>=0.8.0 click>=7.0 configobj json5 PyYAML toml xmltodict anymarkup-0.8.1/setup.cfg0000644000076500000240000000004613516252746017216 0ustar slavek.kabrdastaff00000000000000[egg_info] tag_build = tag_date = 0 anymarkup-0.8.1/setup.py0000644000076500000240000000207513516252612017103 0ustar slavek.kabrdastaff00000000000000#!/usr/bin/env python3 # -*- coding: utf-8 -*- from setuptools import setup setup( name='anymarkup', version='0.8.1', description='Parse/serialize any markup format', long_description=''.join(open('README.rst').readlines()), keywords='xml, yaml, toml, json, json5, ini', author='Slavek Kabrda', author_email='slavek.kabrda@gmail.com', url='https://github.com/bkabrda/anymarkup', license='BSD', packages=['anymarkup'], install_requires=open('requirements.txt').read().splitlines(), entry_points={ 'console_scripts': [ 'anymarkup = anymarkup.cli:cli' ] }, classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: POSIX :: Linux', 'Programming Language :: Python', 'Programming Language :: Python :: 2.7', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', 'Programming Language :: Python :: 3.5', ] ) anymarkup-0.8.1/test/0000755000076500000240000000000013516252746016354 5ustar slavek.kabrdastaff00000000000000anymarkup-0.8.1/test/__init__.py0000644000076500000240000000003013515572740020454 0ustar slavek.kabrdastaff00000000000000# -*- coding: utf-8 -*- anymarkup-0.8.1/test/data.py0000644000076500000240000000245513516252564017643 0ustar slavek.kabrdastaff00000000000000# -*- coding: utf-8 -*- TEST_DATA_INI="""\ [section] string = foobar number = 1 boolean = False float = 2.1 empty = None """ TEST_DATA_INI_INTERPOLATION="""\ [section] string = foobar [%%(test)s] number = 1 boolean = False float = 2.1 empty = None """ TEST_DATA_JSON = """\ { "section": { "string": "foobar", "number": 1, "boolean": false, "float": 2.1, "empty": null } } """ TEST_DATA_JSON5 = """\ { section: { string: "foobar", number: 1, boolean: false, float: 2.1, empty: null, }, } """ TEST_DATA_TOML = """\ [section] string = "foobar" number = 1 boolean = false float = 2.1 empty = "null" """ TEST_DATA_TOML_WITHOUT_EMPTY = """\ [section] string = "foobar" number = 1 boolean = false float = 2.1 """ TEST_DATA_YAML = """\ section: string: foobar number: 1 boolean: false float: 2.1 empty: null """ TEST_DATA_YAML_SORTED = """\ section: boolean: false empty: null float: 2.1 number: 1 string: foobar""" TEST_DATA_YAML_FROM_XML = """\ !!omap - section: !!omap - string: foobar - number: 1 - boolean: false - float: 2.1 - empty: null""" TEST_DATA_XML = """\
foobar 1 false 2.1
""" anymarkup-0.8.1/test/test_cli.py0000644000076500000240000000246713515572740020543 0ustar slavek.kabrdastaff00000000000000# -*- coding: utf-8 -*- from anymarkup import __version__ from anymarkup.cli import cli from click.testing import CliRunner import pytest @pytest.fixture(scope="class") def runner(): return CliRunner() # Testing the CLI outside the conversion arguments class TestCli(): def test_no_arguments(self, runner): result = runner.invoke(cli) assert result.exit_code == 0 assert not result.exception def test_invalid_command(self, runner): result = runner.invoke(cli, ['--foobar']) assert result.exit_code != 0 assert result.exception def test_help(self, runner): result = runner.invoke(cli, ['--help']) assert result.exit_code == 0 assert not result.exception def test_convert_help(self, runner): result = runner.invoke(cli, ['convert', '--help']) assert result.exit_code == 0 assert not result.exception def test_version(self, runner): result = runner.invoke(cli, ['--version']) assert result.exit_code == 0 assert not result.exception assert result.output == 'anymarkup, version ' + __version__ + '\n' def test_convert_invalid_file(self, runner): result = runner.invoke(cli, ['convert', 'foobar']) assert result.exit_code != 0 assert result.exception anymarkup-0.8.1/test/test_cli_ini.py0000644000076500000240000000766013516252564021402 0ustar slavek.kabrdastaff00000000000000# -*- coding: utf-8 -*- from anymarkup.cli import cli from click.testing import CliRunner import pytest from .data import TEST_DATA_INI, TEST_DATA_INI_INTERPOLATION @pytest.fixture(scope="class") def runner(): return CliRunner() # Testing conversion from INI class TestConversionFromIni(): def test_convert_no_error(self, runner): arguments = [ ['convert'], ['convert', '--from-format', 'ini'], ['convert', '--from-format', 'ini', '--to-format', 'ini'], ['convert', '--from-format', 'ini', '--to-format', 'json'], ['convert', '--from-format', 'ini', '--to-format', 'json5'], ['convert', '--from-format', 'ini', '--to-format', 'toml'], ['convert', '--from-format', 'ini', '--to-format', 'xml'], ['convert', '--from-format', 'ini', '--to-format', 'yaml'] ] for args in arguments: result = runner.invoke(cli, args, input=TEST_DATA_INI) assert result.exit_code == 0 assert not result.exception def test_wrong_input_format(self, runner): arguments = [ ['convert', '--from-format', 'json'], ['convert', '--from-format', 'json5'], ['convert', '--from-format', 'toml'], ['convert', '--from-format', 'xml'], ['convert', '--from-format', 'yaml'], ] for args in arguments: result = runner.invoke(cli, args, input=TEST_DATA_INI) assert result.exit_code != 0 assert result.exception def test_interpolation_in_file_fail(self, runner): arguments = [ ['convert', '--from-format', 'ini'], ['convert', '--from-format', 'json'], ['convert', '--from-format', 'json5'], ['convert', '--from-format', 'toml'], ['convert', '--from-format', 'xml'], ['convert', '--from-format', 'yaml'], ] for args in arguments: result = runner.invoke(cli, args, input=TEST_DATA_INI_INTERPOLATION) assert result.exit_code != 0 assert result.exception def test_convert_interpolation_option_fail(self, runner): arguments = [ ['convert', '--interpolate'], ['convert', '--interpolate', '--from-format', 'ini'], ['convert', '--interpolate', '--from-format', 'ini', '--to-format', 'ini'], ['convert', '--interpolate', '--from-format', 'ini', '--to-format', 'json'], ['convert', '--interpolate', '--from-format', 'ini', '--to-format', 'json5'], ['convert', '--interpolate', '--from-format', 'ini', '--to-format', 'toml'], ['convert', '--interpolate', '--from-format', 'ini', '--to-format', 'xml'], ['convert', '--interpolate', '--from-format', 'ini', '--to-format', 'yaml'] ] for args in arguments: result = runner.invoke(cli, args, input=TEST_DATA_INI_INTERPOLATION) assert result.exit_code != 0 assert result.exception def test_convert_interpolation_off_no_error(self, runner): arguments = [ ['convert', '--no-interpolate'], ['convert', '--no-interpolate', '--from-format', 'ini'], ['convert', '--no-interpolate', '--from-format', 'ini', '--to-format', 'ini'], ['convert', '--no-interpolate', '--from-format', 'ini', '--to-format', 'json'], ['convert', '--no-interpolate', '--from-format', 'ini', '--to-format', 'json5'], ['convert', '--no-interpolate', '--from-format', 'ini', '--to-format', 'toml'], ['convert', '--no-interpolate', '--from-format', 'ini', '--to-format', 'xml'], ['convert', '--no-interpolate', '--from-format', 'ini', '--to-format', 'yaml'] ] for args in arguments: result = runner.invoke(cli, args, input=TEST_DATA_INI_INTERPOLATION) assert result.exit_code == 0 assert not result.exceptionanymarkup-0.8.1/test/test_cli_json.py0000644000076500000240000000343213515572740021565 0ustar slavek.kabrdastaff00000000000000# -*- coding: utf-8 -*- from anymarkup.cli import cli from click.testing import CliRunner import pytest from .data import TEST_DATA_JSON @pytest.fixture(scope="class") def runner(): return CliRunner() # Testing conversion from JSON class TestConversionFromJson(): def test_convert_no_error(self, runner): arguments = [ ['convert'], ['convert', '--from-format', 'json'], ['convert', '--from-format', 'json', '--to-format', 'ini'], ['convert', '--from-format', 'json', '--to-format', 'json'], ['convert', '--from-format', 'json', '--to-format', 'json5'], ['convert', '--from-format', 'json', '--to-format', 'toml'], ['convert', '--from-format', 'json', '--to-format', 'xml'], ['convert', '--from-format', 'json', '--to-format', 'yaml'] ] for args in arguments: result = runner.invoke(cli, args, input=TEST_DATA_JSON) assert result.exit_code == 0 assert not result.exception def test_wrong_input_format_still_works(self, runner): arguments = [ ['convert', '--from-format', 'json5'], ['convert', '--from-format', 'yaml'], ] for args in arguments: result = runner.invoke(cli, args, input=TEST_DATA_JSON) assert result.exit_code == 0 assert not result.exception def test_wrong_input_format(self, runner): arguments = [ ['convert', '--from-format', 'ini'], ['convert', '--from-format', 'toml'], ['convert', '--from-format', 'xml'], ] for args in arguments: result = runner.invoke(cli, args, input=TEST_DATA_JSON) assert result.exit_code != 0 assert result.exception anymarkup-0.8.1/test/test_cli_json5.py0000644000076500000240000000345013515572740021652 0ustar slavek.kabrdastaff00000000000000# -*- coding: utf-8 -*- from anymarkup.cli import cli from click.testing import CliRunner import pytest from .data import TEST_DATA_JSON5 @pytest.fixture(scope="class") def runner(): return CliRunner() # Testing conversion from JSON5 class TestConversionFromJson5(): def test_convert_no_error(self, runner): arguments = [ ['convert'], ['convert', '--from-format', 'json5'], ['convert', '--from-format', 'json5', '--to-format', 'ini'], ['convert', '--from-format', 'json5', '--to-format', 'json'], ['convert', '--from-format', 'json5', '--to-format', 'json5'], ['convert', '--from-format', 'json5', '--to-format', 'toml'], ['convert', '--from-format', 'json5', '--to-format', 'xml'], ['convert', '--from-format', 'json5', '--to-format', 'yaml'] ] for args in arguments: result = runner.invoke(cli, args, input=TEST_DATA_JSON5) assert result.exit_code == 0 assert not result.exception def test_wrong_input_format_still_works(self, runner): arguments = [ ['convert', '--from-format', 'yaml'], ] for args in arguments: result = runner.invoke(cli, args, input=TEST_DATA_JSON5) assert result.exit_code == 0 assert not result.exception def test_wrong_input_format(self, runner): arguments = [ ['convert', '--from-format', 'ini'], ['convert', '--from-format', 'json'], ['convert', '--from-format', 'toml'], ['convert', '--from-format', 'xml'], ] for args in arguments: result = runner.invoke(cli, args, input=TEST_DATA_JSON5) assert result.exit_code != 0 assert result.exception anymarkup-0.8.1/test/test_cli_toml.py0000644000076500000240000000343413515572740021571 0ustar slavek.kabrdastaff00000000000000# -*- coding: utf-8 -*- from anymarkup.cli import cli from click.testing import CliRunner import pytest from .data import TEST_DATA_TOML @pytest.fixture(scope="class") def runner(): return CliRunner() # Testing conversion from TOML class TestConversionFromToml(): def test_convert_no_error(self, runner): arguments = [ ['convert'], ['convert', '--from-format', 'toml'], ['convert', '--from-format', 'toml', '--to-format', 'ini'], ['convert', '--from-format', 'toml', '--to-format', 'json'], ['convert', '--from-format', 'toml', '--to-format', 'json5'], ['convert', '--from-format', 'toml', '--to-format', 'toml'], ['convert', '--from-format', 'toml', '--to-format', 'xml'], ['convert', '--from-format', 'toml', '--to-format', 'yaml'] ] for args in arguments: result = runner.invoke(cli, args, input=TEST_DATA_TOML) assert result.exit_code == 0 assert not result.exception def test_wrong_input_format_still_works(self, runner): arguments = [ ['convert', '--from-format', 'ini'], ] for args in arguments: result = runner.invoke(cli, args, input=TEST_DATA_TOML) assert result.exit_code == 0 assert not result.exception def test_wrong_input_format(self, runner): arguments = [ ['convert', '--from-format', 'json'], ['convert', '--from-format', 'json5'], ['convert', '--from-format', 'xml'], ['convert', '--from-format', 'yaml'], ] for args in arguments: result = runner.invoke(cli, args, input=TEST_DATA_TOML) assert result.exit_code != 0 assert result.exception anymarkup-0.8.1/test/test_cli_xml.py0000644000076500000240000000300113515572740021404 0ustar slavek.kabrdastaff00000000000000# -*- coding: utf-8 -*- from anymarkup.cli import cli from click.testing import CliRunner import pytest from .data import TEST_DATA_XML @pytest.fixture(scope="class") def runner(): return CliRunner() # Testing conversion from XML class TestConversionFromXml(): def test_convert_no_error(self, runner): arguments = [ ['convert'], ['convert', '--from-format', 'xml'], ['convert', '--from-format', 'xml', '--to-format', 'ini'], ['convert', '--from-format', 'xml', '--to-format', 'json'], ['convert', '--from-format', 'xml', '--to-format', 'json5'], ['convert', '--from-format', 'xml', '--to-format', 'toml'], ['convert', '--from-format', 'xml', '--to-format', 'xml'], ['convert', '--from-format', 'xml', '--to-format', 'yaml'] ] for args in arguments: result = runner.invoke(cli, args, input=TEST_DATA_XML) assert result.exit_code == 0 assert not result.exception def test_wrong_input_format(self, runner): arguments = [ ['convert', '--from-format', 'ini'], ['convert', '--from-format', 'json'], ['convert', '--from-format', 'json5'], ['convert', '--from-format', 'toml'], ['convert', '--from-format', 'yaml'], ] for args in arguments: result = runner.invoke(cli, args, input=TEST_DATA_XML) assert result.exit_code != 0 assert result.exception anymarkup-0.8.1/test/test_cli_yaml.py0000644000076500000240000000301213515572740021550 0ustar slavek.kabrdastaff00000000000000# -*- coding: utf-8 -*- from anymarkup.cli import cli from click.testing import CliRunner import pytest from .data import TEST_DATA_YAML @pytest.fixture(scope="class") def runner(): return CliRunner() # Testing conversion from XML class TestConversionFromXml(): def test_convert_no_error(self, runner): arguments = [ ['convert'], ['convert', '--from-format', 'yaml'], ['convert', '--from-format', 'yaml', '--to-format', 'ini'], ['convert', '--from-format', 'yaml', '--to-format', 'json'], ['convert', '--from-format', 'yaml', '--to-format', 'json5'], ['convert', '--from-format', 'yaml', '--to-format', 'toml'], ['convert', '--from-format', 'yaml', '--to-format', 'xml'], ['convert', '--from-format', 'yaml', '--to-format', 'yaml'] ] for args in arguments: result = runner.invoke(cli, args, input=TEST_DATA_YAML) assert result.exit_code == 0 assert not result.exception def test_wrong_input_format(self, runner): arguments = [ ['convert', '--from-format', 'ini'], ['convert', '--from-format', 'json'], ['convert', '--from-format', 'json5'], ['convert', '--from-format', 'toml'], ['convert', '--from-format', 'xml'], ] for args in arguments: result = runner.invoke(cli, args, input=TEST_DATA_YAML) assert result.exit_code != 0 assert result.exception anymarkup-0.8.1/test/test_imports.py0000644000076500000240000000035113515572740021457 0ustar slavek.kabrdastaff00000000000000# -*- coding: utf-8 -*- import anymarkup, anymarkup_core def test_imports(): for i in ['AnyMarkupError', 'parse', 'parse_file', 'serialize', 'serialize_file']: assert getattr(anymarkup, i) is getattr(anymarkup_core, i)