-
Notifications
You must be signed in to change notification settings - Fork 2
/
test_codes.py
152 lines (130 loc) · 5.53 KB
/
test_codes.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import datetime
import pytest
from anchorpoint.textselectors import TextPositionSelector
class TestCodes:
@pytest.mark.parametrize(
"codename, name, level",
[
("usc17", "USC Title 17", "statute"),
("const", "Constitution of the United States", "constitution"),
("cfr37", "Code of Federal Regulations Title 37", "regulation"),
("ca_evid", "California Evidence Code", "statute"),
("ca_pen", "California Penal Code", "statute"),
],
)
def test_making_code(self, make_code, codename, name, level):
code = make_code[codename]
assert str(code) == name
assert code.level == level
def test_cfr_repr(self, make_code):
cfr = make_code["cfr37"]
assert "Title 37" in repr(cfr)
def test_get_code_from_regime_with_partial_uri(self, make_regime):
"""
The regime should return the appropriate "code" even though its
uri is more specific than the query, because it's the only one
available that starts with that.
"""
beard_act = make_regime.get_code("/au/act")
assert "Enlightenment" in str(beard_act)
@pytest.mark.parametrize(
"code, path",
[
("usc17", "/us/usc/t17"),
("const", "/us/const"),
("cfr37", "/us/cfr/t37"),
("ca_evid", "/us-ca/evid"),
("ca_pen", "/us-ca/pen"),
("beard_act", "/au/act/1934/47"),
],
)
def test_code_urls(self, make_code, code, path):
assert make_code[code].uri == path
@pytest.mark.parametrize(
"code, expected",
[
("usc17", "Title 17"),
("const", "Constitution of the United States"),
("cfr37", "Code of Federal Regulations Title 37"),
("ca_evid", "California Evidence Code"),
("ca_pen", "California Penal Code"),
],
)
def test_code_title(self, make_code, code, expected):
assert make_code[code].title == expected
def test_code_select_text(self, make_code):
code = make_code["beard_act"]
text = code.select_text("/au/act/1934/47/1")
assert text.startswith("This Act may be cited")
def test_code_select_text_chapeau(self, make_code):
code = make_code["beard_act"]
text = code.select_text("/au/act/1934/47/1/4/chapeau")
assert text.startswith("In this Act, beard means")
def test_get_bill_of_rights_effective_date(self, make_code):
const = make_code["const"]
bill_of_rights_date = datetime.date(1791, 12, 15)
assert const.provision_effective_date("amendment-V") == bill_of_rights_date
def test_get_14th_A_effective_date(self, make_code):
const = make_code["const"]
equal_protection_date = datetime.date(1868, 7, 28)
assert const.provision_effective_date("amendment-XIV") == equal_protection_date
def test_format_uri_for_const(self, make_code):
"""
This should test the example in the docstring
for the Code.format_uri_for_const method.
"""
const = make_code["const"]
out = const.format_uri_for_const("/us/const/amendment/XIV/1")
assert out == "amendment-XIV-1"
@pytest.mark.parametrize(
"path, expected",
(
["/us/const/amendment-XIV/3", "No person shall be a Senator"],
["/article-I/5/1", "Each House shall be the Judge"],
),
)
def test_get_section_from_fed_const(self, make_code, path, expected):
const = make_code["const"]
section = const.get_fed_const_section(path)
assert section.find("text").text.startswith(expected)
def test_text_interval_from_entire_code(self, make_code):
interval = make_code["const"].select_text_from_interval(
interval=TextPositionSelector(16, 50)
)
assert interval.startswith("Powers herein granted")
def test_text_interval_constitution_section(self, make_code):
passage = make_code["const"].select_text_from_interval(
path="/us/const/article-I/3/7", interval=TextPositionSelector(66, 85)
)
assert passage == "removal from Office"
def test_text_interval_entire_section(self, make_code):
"""
Returns an interval covering the entire 317-character section.
"""
interval = make_code["const"].text_interval(path="/us/const/article-I/3/7")
assert interval == (0, 317)
def test_text_interval_beyond_end_of_section(self, make_code):
with pytest.raises(IndexError):
_ = make_code["const"].select_text_from_interval(
path="/us/const/article-I/3/7", interval=TextPositionSelector(66, 400)
)
def test_text_interval_absent_section(self, make_code):
"""
The path is a section that doesn't exist in CFR.
"""
with pytest.raises(ValueError):
_ = make_code["cfr37"].select_text_from_interval(
path="/us/const/article-I/3/7", interval=TextPositionSelector(0, 66)
)
def test_text_interval_bad_source(self, make_code, make_selector):
with pytest.raises(ValueError):
_ = make_code["usc17"].text_interval(
selector=make_selector["bad_selector"], path="/us/const/amendment-IV",
)
def test_text_interval_bad_selector(self, make_code, make_selector):
assert (
make_code["const"].text_interval(
selector=make_selector["bad_selector"], path="/us/const/amendment-IV",
)
is None
)