Completed
Push — master ( 6ef2f5...b75cb1 )
by Satoru
53s
created

Test00.test_30_load__ignore_missing()   A

Complexity

Conditions 2

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
#
2
# Copyright (C) 2012 - 2015 Satoru SATOH <ssato @ redhat.com>
3
# License: MIT
4
#
5
# pylint: disable=missing-docstring, protected-access, invalid-name
6
from __future__ import absolute_import
7
8
import os
9
import os.path
10
import unittest
11
12
import anyconfig.backend.base as TT  # stands for test target
13
import anyconfig.backends
14
import tests.common
15
16
17
MZERO = TT.Parser()._container_factory()()
18
19
20
class Test00(unittest.TestCase):
21
22
    def setUp(self):
23
        self.psr = TT.Parser()
24
25
    def test_10_type(self):
26
        self.assertEqual(self.psr.type(), TT.Parser._type)
27
28
    def test_20_loads__null_content(self):
29
        cnf = self.psr.loads('')
30
        self.assertEqual(cnf, MZERO)
31
        self.assertTrue(isinstance(cnf, type(MZERO)))
32
33
    def test_30_load__ac_ignore_missing(self):
34
        cpath = os.path.join(os.curdir, "conf_file_not_exist.json")
35
        assert not os.path.exists(cpath)
36
37
        ioi = anyconfig.backends.inspect_io_obj(cpath)
38
        cnf = self.psr.load(ioi, ac_ignore_missing=True)
39
        self.assertEqual(cnf, MZERO)
40
        self.assertTrue(isinstance(cnf, type(MZERO)))
41
42
43
class Test10(unittest.TestCase):
44
45
    def setUp(self):
46
        self.workdir = tests.common.setup_workdir()
47
48
    def tearDown(self):
49
        tests.common.cleanup_workdir(self.workdir)
50
51
    def test_10_ensure_outdir_exists(self):
52
        TT.LOGGER.setLevel(TT.logging.WARN)  # suppress info/debug log msgs.
53
        outdir = os.path.join(self.workdir, "outdir")
54
        outfile = os.path.join(outdir, "a.txt")
55
        TT.ensure_outdir_exists(outfile)
56
57
        self.assertTrue(os.path.exists(outdir))
58
59
    def test_12_ensure_outdir_exists__no_dir(self):
60
        TT.ensure_outdir_exists("a.txt")
61
        self.assertFalse(os.path.exists(os.path.dirname("a.txt")))
62
63
64
class Test20(unittest.TestCase):
65
66
    def test_10_TextFilesMixin_ropen(self):
67
        with TT.TextFilesMixin.ropen("/dev/null") as fileobj:
68
            self.assertEqual(fileobj.mode, 'r')
69
70
    def test_10_TextFilesMixin_wopen(self):
71
        with TT.TextFilesMixin.wopen("/dev/null") as fileobj:
72
            self.assertEqual(fileobj.mode, 'w')
73
74
    def test_20_BinaryFilesMixin_ropen(self):
75
        with TT.BinaryFilesMixin.ropen("/dev/null") as fileobj:
76
            self.assertEqual(fileobj.mode, 'rb')
77
78
    def test_20_BinaryFilesMixin_wopen(self):
79
        with TT.BinaryFilesMixin.wopen("/dev/null") as fileobj:
80
            self.assertEqual(fileobj.mode, 'wb')
81
82
# vim:sw=4:ts=4:et:
83