This repository was archived by the owner on Mar 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathone_test.py
More file actions
54 lines (38 loc) · 1.23 KB
/
one_test.py
File metadata and controls
54 lines (38 loc) · 1.23 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
import pytest
import re
from pyby import EnumerableList
@pytest.fixture
def empty_list():
return EnumerableList()
@pytest.fixture
def numbers():
return EnumerableList([1, 2, 3])
def test_one(empty_list, numbers):
assert not numbers.one()
assert not empty_list.one()
assert not EnumerableList([False]).one()
assert EnumerableList([True]).one()
def test_one_with_an_object(numbers):
assert numbers.one(3)
assert not numbers.one(4)
def test_one_with_a_predicate(empty_list, numbers):
assert EnumerableList([0]).one(is_zero)
assert not empty_list.one(is_zero)
assert not numbers.one(is_zero)
def test_one_with_a_regex_pattern(numbers):
string_pattern = re.compile(r"\d")
assert not numbers.one(string_pattern)
numbers.append("the number 69")
assert numbers.one(string_pattern)
numbers.append("another number 69")
assert not numbers.one(string_pattern)
bytes_pattern = re.compile(r"\d".encode())
assert not numbers.one(bytes_pattern)
numbers.append(b"binary 420")
assert numbers.one(bytes_pattern)
def test_one_with_a_class(numbers):
assert not numbers.one(int)
numbers.append(1.23)
assert numbers.one(float)
def is_zero(element):
return element == 0