File: test_libs_not_installed.py

package info (click to toggle)
anymarkup-core 0.8.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 212 kB
  • sloc: python: 730; xml: 12; makefile: 3
file content (38 lines) | stat: -rw-r--r-- 1,425 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
from flexmock import flexmock
import pytest
import yaml

import anymarkup_core


class TestLibsNotInstalled(object):
    # json is always there, since we only support Python >= 2.7
    @pytest.mark.parametrize(('fmt', 'lib'), [
        ('ini', 'configobj'),
        ('xml', 'xmltodict'),
        ('yaml', 'yaml'),
    ])
    def test_raises_proper_error(self, fmt, lib):
        flexmock(anymarkup_core).should_receive(lib).and_return(None)
        flexmock(anymarkup_core).should_receive('fmt_to_lib').and_return({fmt: (None, lib)})

        with pytest.raises(anymarkup_core.AnyMarkupError):
            anymarkup_core.parse('', format=fmt)

        with pytest.raises(anymarkup_core.AnyMarkupError):
            anymarkup_core.serialize('', format=fmt)

    def test_uninstalled_dep_doesnt_make_parsing_fail_for_installed_deps(self):
        flexmock(anymarkup_core).should_receive('configobj').and_return(None)
        flexmock(anymarkup_core).should_receive('fmt_to_lib').\
            and_return({'ini': (None, ''), 'yaml': (yaml, '')})

        with pytest.raises(anymarkup_core.AnyMarkupError):
            anymarkup_core.parse('', format='ini')

        assert anymarkup_core.parse('foo: bar') == {'foo': 'bar'}

        with pytest.raises(anymarkup_core.AnyMarkupError):
            anymarkup_core.serialize('', format='ini')

        assert anymarkup_core.serialize({'foo': 'bar'}, format='yaml') == b'foo: bar\n'