-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathconftest.py
242 lines (209 loc) · 10.2 KB
/
conftest.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
from pathlib import Path
import pytest
from django.db import connection
from docs.models import (
Album,
Artist,
Track,
)
# pragma: no cover
def pytest_runtest_setup(item):
django_marker = item.get_closest_marker("django_db") or item.get_closest_marker("django")
if django_marker is not None:
try:
import django # noqa: F401
except ImportError:
pytest.skip("test requires django")
flask_marker = item.get_closest_marker("flask")
if flask_marker is not None:
try:
import flask # noqa: F401
except ImportError:
pytest.skip('test requires flask')
@pytest.hookimpl(trylast=True)
def pytest_collection_modifyitems(session, config, items):
items[:] = sorted(items, key=lambda x: x.fspath)
def pytest_sessionstart(session):
from iommi.docs import generate_api_docs_tests, write_rst_from_pytest
write_rst_from_pytest()
generate_api_docs_tests((Path(__file__).parent / 'docs').absolute())
write_rst_from_pytest()
@pytest.fixture(autouse=True)
def reset_sequences(request, django_db_blocker):
if request.node.get_closest_marker('django_db'):
with django_db_blocker.unblock():
cursor = connection.cursor()
# noinspection SqlResolve
cursor.execute("SELECT name FROM sqlite_master WHERE type='table'")
for i, (table,) in enumerate(cursor.fetchall()):
cursor.execute(f"""
INSERT INTO SQLITE_SEQUENCE (name,seq) SELECT '{table}', {(i + 1) * 1000} WHERE NOT EXISTS
(SELECT changes() AS change FROM sqlite_sequence WHERE change <> 0);
""")
@pytest.fixture
def artist(transactional_db):
return Artist.objects.create(name='Black Sabbath')
@pytest.fixture
def album(artist):
return Album.objects.create(name='Heaven & Hell', artist=artist, year=1980)
@pytest.fixture
def track(album):
return Track.objects.create(album=album, name='Neon Knights', index=1)
@pytest.fixture
def small_discography(artist):
return [
Album.objects.get_or_create(name='Heaven & Hell', artist=artist, year=1980)[0],
Album.objects.get_or_create(name='Mob Rules', artist=artist, year=1981)[0],
]
@pytest.fixture
def medium_discography(artist):
ozzy, _ = Artist.objects.get_or_create(name='Ozzy Osbourne')
return [
Album.objects.get_or_create(name='Heaven & Hell', artist=artist, year=1980)[0],
Album.objects.get_or_create(name='Blizzard of Ozz', artist=ozzy, year=1980)[0],
Album.objects.get_or_create(name='Mob Rules', artist=artist, year=1981)[0],
]
def create_tracks(album_name, tracks):
album = Album.objects.get(name=album_name)
Track.objects.bulk_create(
[
Track(
album=album,
name=name,
index=i + 1,
)
for i, name in enumerate(tracks)
]
)
@pytest.fixture
def big_discography(medium_discography):
create_tracks(
'Heaven & Hell',
[
'Neon Knights',
'Children of the Sea',
'Lady Evil',
'Heaven and Hell',
'Wishing Well',
'Die Young',
'Walk Away',
'Lonely Is the Word',
],
)
create_tracks(
'Blizzard of Ozz',
[
'I Don\'t Know',
'Crazy Train',
'Goodbye to Romance',
'Dee',
'Suicide Solution',
'Mr. Crowley',
'No Bone Movies',
'Revelation (Mother Earth)',
'Steal Away (The Night)',
],
)
create_tracks(
'Mob Rules',
[
'Turn Up the Night',
'Voodoo',
'The Sign of the Southern Cross',
'E5150" (instrumental',
'The Mob Rules',
'Country Girl',
'Slipping Away',
'Falling Off the Edge of the World',
'Over and Over',
],
)
@pytest.fixture
def really_big_discography():
albums = [
{'artist': 'Black Sabbath', 'name': '13', 'year': 2013},
{'artist': 'Dio', 'name': 'Angry Machines', 'year': 1996},
{'artist': 'Dio', 'name': 'At Donington UK: Live 1983 & 1987', 'year': 2010},
{'artist': 'Ozzy Osbourne', 'name': 'Bark At The Moon', 'year': 1983},
{'artist': 'Black Sabbath', 'name': 'Black Sabbath', 'year': 1970},
{'artist': 'Black Sabbath', 'name': 'Black Sabbath Vol 4', 'year': 1972},
{'artist': 'Ozzy Osbourne', 'name': 'Blizzard Of Ozz', 'year': 1980},
{'artist': 'Black Sabbath', 'name': 'Born Again', 'year': 1983},
{'artist': 'Black Sabbath', 'name': 'Captured Live!', 'year': 1983},
{'artist': 'Black Sabbath', 'name': 'Cross Purposes', 'year': 1994},
{'artist': 'Black Sabbath', 'name': 'Cross Purposes - Live', 'year': 1995},
{'artist': 'Black Sabbath', 'name': 'Dehumanizer', 'year': 1992},
{'artist': 'Ozzy Osbourne', 'name': 'Diary Of A Madman', 'year': 1981},
{'artist': 'Dio', 'name': "Dio's Inferno - The Last In Live", 'year': 1997},
{'artist': 'Django Reinhardt', 'name': 'Django', 'year': 1957},
{'artist': 'Django Reinhardt', 'name': 'Django (Volume 1)', 'year': 1957},
{'artist': 'Django Reinhardt', 'name': 'Django Reinhardt', 'year': 1961},
{'artist': 'Django Reinhardt', 'name': 'Django Volume V', 'year': 1959},
{'artist': 'Ozzy Osbourne', 'name': 'Down To Earth', 'year': 2001},
{'artist': 'Dio', 'name': 'Dream Evil', 'year': 1987},
{'artist': 'Dio', 'name': 'Evil Or Divine: Live In New York City', 'year': 2003},
{'artist': 'Dio', 'name': 'Finding The Sacred Heart – Live In Philly 1986 –', 'year': 2013},
{'artist': 'Black Sabbath', 'name': 'Forbidden', 'year': 1995},
{'artist': 'Tony Iommi', 'name': 'Fused', 'year': 2005},
{'artist': 'Black Sabbath', 'name': 'Headless Cross', 'year': 1989},
{'artist': 'Black Sabbath', 'name': 'Heaven And Hell', 'year': 1980},
{'artist': 'Dio', 'name': 'Holy Diver', 'year': 1983},
{'artist': 'Dio', 'name': 'Holy Diver Live', 'year': 2006},
{'artist': 'Dio', 'name': 'Intermission', 'year': 1986},
{'artist': 'Tony Iommi', 'name': 'Iommi', 'year': 2000},
{'artist': 'Dio', 'name': 'Killing The Dragon', 'year': 2002},
{'artist': 'Ozzy Osbourne', 'name': 'Live & Loud', 'year': 1993},
{'artist': 'Dio', 'name': 'Live - We Rock', 'year': 2010},
{'artist': 'Ozzy Osbourne', 'name': 'Live At Budokan', 'year': 2002},
{'artist': 'Black Sabbath', 'name': 'Live At Hammersmith Odeon', 'year': 2007},
{'artist': 'Black Sabbath', 'name': 'Live At Last', 'year': 1980},
{'artist': 'Black Sabbath', 'name': 'Live Evil', 'year': 1982},
{'artist': 'Dio', 'name': 'Live In London Hammersmith Apollo 1993', 'year': 2014},
{'artist': 'Black Sabbath', 'name': 'Live...Gathered In Their Masses', 'year': 2013},
{'artist': 'Dio', 'name': 'Lock Up The Wolves', 'year': 1990},
{'artist': 'Dio', 'name': 'Magica', 'year': 2000},
{'artist': 'Black Sabbath', 'name': 'Master Of Reality', 'year': 1971},
{'artist': 'Dio', 'name': 'Master Of The Moon', 'year': 2004},
{'artist': 'Black Sabbath', 'name': 'Mob Rules', 'year': 1981},
{'artist': 'Black Sabbath', 'name': 'Never Say Die!', 'year': 1978},
{'artist': 'Django Reinhardt', 'name': 'Newly Discovered Masters By Django Reinhardt And The Quintet Of The Hot Club Of France', 'year': 1961},
{'artist': 'Ozzy Osbourne', 'name': 'No More Tears', 'year': 1991},
{'artist': 'Ozzy Osbourne', 'name': 'Off The Record Specials With Mary Turner', 'year': 1987},
{'artist': 'Ozzy Osbourne', 'name': 'Ordinary Man', 'year': 2020},
{'artist': 'Ozzy Osbourne', 'name': 'Ozzmosis', 'year': 1995},
{'artist': 'Ozzy Osbourne', 'name': 'Ozzy Live', 'year': 2012},
{'artist': 'Black Sabbath', 'name': 'Paranoid', 'year': 1970},
{'artist': 'Black Sabbath', 'name': 'Past Lives', 'year': 2002},
{'artist': 'Black Sabbath', 'name': 'Reunion', 'year': 1998},
{'artist': 'Black Sabbath', 'name': 'Sabbath Bloody Sabbath', 'year': 1973},
{'artist': 'Black Sabbath', 'name': 'Sabotage', 'year': 1975},
{'artist': 'Dio', 'name': 'Sacred Heart', 'year': 1985},
{'artist': 'Ozzy Osbourne', 'name': 'Scream', 'year': 2010},
{'artist': 'Django Reinhardt', 'name': 'Souvenirs De Django Reinhardt Volume 2', 'year': 1954},
{'artist': 'Ozzy Osbourne', 'name': 'Speak Of The Devil', 'year': 1982},
{'artist': 'Dio', 'name': 'Strange Highways', 'year': 1993},
{'artist': 'Quintette Du Hot Club De France', 'name': "Swing '35-'39", 'year': 1970},
{'artist': 'Black Sabbath', 'name': 'Technical Ecstasy', 'year': 1976},
{'artist': 'Black Sabbath', 'name': 'The End', 'year': 2016},
{'artist': 'Black Sabbath', 'name': 'The End (4 February 2017 - Birmingham)', 'year': 2017},
{'artist': 'Black Sabbath', 'name': 'The Eternal Idol', 'year': 1987},
{'artist': 'Django Reinhardt', 'name': 'The Great Artistry Of Django Reinhardt', 'year': 1953},
{'artist': 'Ozzy Osbourne', 'name': 'The King Biscuit Flower Hour (#642)', 'year': 1986},
{'artist': 'Dio', 'name': 'The Last In Line', 'year': 1984},
{'artist': 'Quintette Du Hot Club De France', 'name': 'The Quintet Of The Hot Club Of France - Volume 2', 'year': 1943},
{'artist': 'Ozzy Osbourne', 'name': 'The Ultimate Sin', 'year': 1986},
{'artist': 'Black Sabbath', 'name': 'Tyr', 'year': 1990},
{'artist': 'Ozzy Osbourne', 'name': 'Under Cover', 'year': 2005},
{'artist': 'Django Reinhardt', 'name': 'Volume 2', 'year': 1957},
{'artist': 'Damnation', 'name': 'album 10', 'year': 1980},
{'artist': 'Damnation', 'name': 'album 9', 'year': 1980},
]
artist_by_name = {}
for artist in {x['artist'] for x in albums}:
artist_by_name[artist] = Artist.objects.create(name=artist)
for album in albums:
Album.objects.create(
name=album['name'],
artist=artist_by_name[album['artist']],
year=album['year'],
)