File: test_option_nounset.py

package info (click to toggle)
python-expandvars 1.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 360 kB
  • sloc: python: 656; makefile: 3
file content (42 lines) | stat: -rw-r--r-- 1,095 bytes parent folder | download | duplicates (2)
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
# -*- coding: utf-8 -*-

import importlib
from os import environ as env
from unittest.mock import patch

import pytest

import expandvars


@patch.dict(env, {}, clear=True)
def test_expandvars_option_nounset():
    importlib.reload(expandvars)

    assert expandvars.expandvars("$FOO") == ""

    with pytest.raises(
        expandvars.ExpandvarsException, match="FOO: unbound variable"
    ) as e:
        expandvars.expandvars("$FOO", nounset=True)

    assert isinstance(e.value, expandvars.UnboundVariable)

    with pytest.raises(
        expandvars.ExpandvarsException, match="FOO: unbound variable"
    ) as e:
        expandvars.expandvars("${FOO}", nounset=True)

    assert isinstance(e.value, expandvars.UnboundVariable)


@patch.dict(env, {}, clear=True)
def test_expandvars_option_nounset_with_strict():
    importlib.reload(expandvars)

    with pytest.raises(
        expandvars.ExpandvarsException, match="FOO: parameter null or not set"
    ) as e:
        assert expandvars.expandvars("${FOO:?}", nounset=True)

    assert isinstance(e.value, expandvars.ParameterNullOrNotSet)