def test_error(self): os.environ['BOOL_EMPTY'] = '' with self.assertRaises(TypeError): parsenvy.bool('BOOL_EMPTY') os.environ['BOOL_STR'] = 'nope' with self.assertRaises(TypeError): parsenvy.bool('BOOL_STR')
def test_bool_true_word(monkeypatch): monkeypatch.setenv("foo", "TrUe") # capitalization is intentional assert parsenvy.bool("foo") is True
def test_bool_empty(monkeypatch): monkeypatch.setenv("foo", "") with pytest.raises(ValueError): parsenvy.bool("foo")
def test_bool_numbers(monkeypatch): monkeypatch.setenv("foo", "01") with pytest.raises(ValueError): parsenvy.bool("foo")
def test_bool_neither(monkeypatch): monkeypatch.setenv("foo", "bar") with pytest.raises(ValueError): parsenvy.bool("foo")
def test_bool_false_number(monkeypatch): monkeypatch.setenv("foo", "0") assert parsenvy.bool("foo") is False
def test_bool_false_word(monkeypatch): monkeypatch.setenv("foo", "fAlSe") # capitalization is intentional assert parsenvy.bool("foo") is False
def test_bool_true_number(monkeypatch): monkeypatch.setenv("foo", "1") assert parsenvy.bool("foo") is True
def test_true(self): os.environ['BOOL_TRUE'] = 'true' self.assertTrue(parsenvy.bool('BOOL_TRUE')) os.environ['BOOL_1'] = '1' self.assertTrue(parsenvy.bool('BOOL_1'))
def test_default(self): self.assertTrue(parsenvy.bool('BOOL_NONE', True))
def test_none(self): self.assertIsNone(parsenvy.bool('BOOL_NONE'))
def test_false(self): os.environ['BOOL_FALSE'] = 'false' self.assertFalse(parsenvy.bool('BOOL_FALSE')) os.environ['BOOL_0'] = '0' self.assertFalse(parsenvy.bool('BOOL_0'))