File: test_const.py

package info (click to toggle)
bme280 0.2.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 260 kB
  • sloc: python: 429; makefile: 206
file content (33 lines) | stat: -rw-r--r-- 773 bytes parent folder | download | duplicates (3)
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
# -*- coding: utf-8 -*-
# Copyright (c) 2018 Richard Hull
# See LICENSE.rst for details.

import bme280.const as c
from bme280.const import ConstError
import pytest

c.const1 = "goodbye"
c.const2 = "cruel"
c.const3 = "world"


def test_simple_assignment():
    assert c.const1 == "goodbye"


def test_to_string():
    assert "'const1': 'goodbye'" in str(c)
    assert "'const2': 'cruel'" in str(c)
    assert "'const3': 'world'" in str(c)


def test_rebind_throws_error():
    with pytest.raises(ConstError) as excinfo:
        del c.const1
    assert "Can't unbind const(const1)" in str(excinfo.value)


def test_unbind_throws_error():
    with pytest.raises(ConstError) as excinfo:
        c.const1 = "hello"
    assert "Can't rebind const(const1)" in str(excinfo.value)