1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
# -*- 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.exception
|