File: test_cli_json5.py

package info (click to toggle)
anymarkup 0.8.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 172 kB
  • sloc: python: 450; makefile: 3
file content (53 lines) | stat: -rw-r--r-- 1,832 bytes parent folder | download
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
# -*- 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