File: test_util.py

package info (click to toggle)
python-dcos 0.2.0-10
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,440 kB
  • sloc: python: 8,196; sh: 194; makefile: 36
file content (30 lines) | stat: -rw-r--r-- 858 bytes parent folder | download | duplicates (4)
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
from dcos import util
from dcos.errors import DCOSException

import pytest


def test_render_mustache_json():
    # x's value expands to a JSON array
    # y's value expands to a JSON object
    # z's value expands to a JSON string
    template = '{ "x": {{{xs}}}, "y": {{{ys}}}, "z": "{{{z}}}"}'
    xs = [1, 2, 3]
    ys = {'y1': 1, 'y2': 2}
    z = 'abc'
    data = {'xs': xs, 'ys': ys, 'z': z}
    result = util.render_mustache_json(template, data)

    assert type(result) is dict
    assert result.get('x') == xs
    assert result.get('y') == ys
    assert result.get('z') == z


def test_open_file():
    path = 'nonexistant_file_name.txt'
    with pytest.raises(DCOSException) as excinfo:
        with util.open_file(path):
            pass
    assert 'Error opening file [{}]: No such file or directory'.format(path) \
        in str(excinfo.value)