File: backend_test.py

package info (click to toggle)
pybtex 0.25.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,628 kB
  • sloc: python: 13,585; makefile: 181; sh: 39; javascript: 29
file content (315 lines) | stat: -rw-r--r-- 8,469 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
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# Copyright (c) 2006-2021  Andrey Golovizin
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


import pytest

from pybtex.database import parse_string
from pybtex.backends.html import Backend as HtmlBackend
from pybtex.style.formatting.unsrt import Style as UnsrtStyle

article_bib = """
@article{article,
  author  = {Peter Adams}, 
  title   = {The title of the work},
  journal = {The name of the journal},
  year    = 1993,
  number  = 2,
  pages   = {201-213},
  month   = 7,
  note    = {An optional note}, 
  volume  = 4
}
"""

article_html = """
Peter Adams.
The title of the work.
<em>The name of the journal</em>, 4(2):201&ndash;213, 7 1993.
An optional note.
"""

book_bib = """@book{book,
  author    = {Peter Babington}, 
  title     = {The title of the work},
  publisher = {The name of the publisher},
  year      = 1993,
  volume    = 4,
  series    = 10,
  address   = {The address},
  edition   = {3rd},
  month     = 7,
  note      = {An optional note},
  isbn      = {3257227892}
}
"""

book_html = """
Peter Babington.
<em>The title of the work</em>.
Volume&nbsp;4 of 10.
The name of the publisher, The address, 3rd edition, 7 1993.
ISBN 3257227892.
An optional note.
"""

booklet_bib = """
@booklet{booklet,
  title        = {The title of the work},
  author       = {Peter Caxton}, 
  howpublished = {How it was published},
  address      = {The address of the publisher},
  month        = jul,
  year         = 1993,
  note         = {An optional note}
}
"""

booklet_html = """
Peter Caxton.
The title of the work.
How it was published, The address of the publisher, July 1993, An optional note.
"""

inbook_bib = """
@inbook{inbook,
  author       = {Peter Eston}, 
  title        = {The title of the work},
  chapter      = 8,
  pages        = {201-213},
  publisher    = {The name of the publisher},
  year         = 1993,
  volume       = 4,
  series       = {The name of the series},
  address      = {The address of the publisher},
  edition      = {3rd},
  month        = 7,
  note         = {An optional note}
}
"""

inbook_html = """
Peter Eston.
<em>The title of the work</em>, chapter&nbsp;8, pages 201&ndash;213.
Volume&nbsp;4 of The name of the series.
The name of the publisher, The address of the publisher, 3rd edition, 7 1993, An optional note.
"""

incollection_bib = """
@incollection{incollection,
  author       = {Peter Farindon}, 
  title        = {The title of the work},
  booktitle    = {The title of the book},
  publisher    = {The name of the publisher},
  year         = 1993,
  editor       = {The editor},
  volume       = 4,
  series       = {The name of the series},
  chapter      = 8,
  pages        = {201-213},
  address      = {The address of the publisher},
  edition      = {3rd},
  month        = aug,
  note         = {An optional note}
}
"""

incollection_html = """
Peter Farindon.
The title of the work.
In The editor, editor, <em>The title of the book</em>, volume&nbsp;4 of The name of the series, chapter&nbsp;8, pages 201&ndash;213.
The name of the publisher, The address of the publisher, 3rd edition, August 1993.
"""

manual_bib = """
@manual{manual,
  title        = {The title of the work},
  author       = {Peter Gainsford}, 
  organization = {The organization},
  address      = {The address of the publisher},
  edition      = {3rd},
  month        = jan,
  year         = 1993,
  note         = {An optional note}
}
"""

manual_html = """
Peter Gainsford.
<em>The title of the work</em>.
The organization, The address of the publisher, 3rd edition, January 1993.
An optional note.
"""

masterthesis_bib = """
@mastersthesis{mastersthesis,
  author       = {Peter Harwood}, 
  title        = {The title of the work},
  school       = {The school of the thesis},
  year         = 1993,
  address      = {The address of the publisher},
  month        = feb,
  note         = {An optional note}
}
"""

masterthesis_html = """
Peter Harwood.
The title of the work.
Master's thesis, The school of the thesis, The address of the publisher, February 1993.
An optional note.
"""

misc_bib = """
@misc{misc,
  author       = {Peter Isley}, 
  title        = {The title of the work},
  howpublished = {How it was published},
  month        = oct,
  year         = 1993,
  note         = {An optional note}
}
"""

misc_html = """
Peter Isley.
The title of the work.
How it was published, October 1993.
An optional note.
"""

phdthesis_bib = """
@phdthesis{phdthesis,
  author       = {Peter Joslin}, 
  title        = {The title of the work},
  school       = {The school of the thesis},
  year         = 1993,
  address      = {The address of the publisher},
  month        = dec,
  note         = {An optional note}
}
"""

phdthesis_html = """
Peter Joslin.
<em>The title of the work</em>.
PhD thesis, The school of the thesis, The address of the publisher, December 1993.
An optional note.
"""

proceedings_bib = """
@proceedings{proceedings,
  title        = {The title of the work},
  year         = 1993,
  editor       = {Peter Kidwelly},
  volume       = 4,
  series       = 5,
  address      = {The address of the publisher},
  month        = oct,
  organization = {The organization},
  publisher    = {The name of the publisher},
  note         = {An optional note}
}
"""

proceedings_html = """
Peter Kidwelly, editor.
<em>The title of the work</em>, volume&nbsp;4 of 5, The address of the publisher, October 1993. The organization, The name of the publisher.
An optional note.
"""

techreport_bib = """
@techreport{techreport,
  author       = {Peter Lambert}, 
  title        = {The title of the work},
  institution  = {The institution that published},
  year         = 1993,
  number       = 2,
  address      = {The address of the publisher},
  month        = nov,
  note         = {An optional note}
}
"""

techreport_html = """
Peter Lambert.
The title of the work.
Technical Report 2, The institution that published, The address of the publisher, November 1993.
An optional note.
"""

unpublished_bib = """
@unpublished{unpublished,
  author       = {Peter Marcheford}, 
  title        = {The title of the work},
  note         = {An optional note},
  month        = mar,
  year         = 1993
}
"""

unpublished_html = """
Peter Marcheford.
The title of the work.
An optional note, March 1993.
"""

online_bib = """
@online{online,
    author = {Peter Nash},
    title = {The title of the work},
    year = 1993,
    url = {http://www.google.com/},
    urldate = {1993-03-07},
}
"""

online_html = """
Peter Nash.
The title of the work.
1993.
URL: <a href="http://www.google.com/">http://www.google.com/</a> (visited on 1993-03-07).
"""


@pytest.mark.parametrize("bib,html", [
    (article_bib, article_html),
    (book_bib, book_html),
    (booklet_bib, booklet_html),
    (inbook_bib, inbook_html),
    (incollection_bib, incollection_html),
    (manual_bib, manual_html),
    (masterthesis_bib, masterthesis_html),
    (misc_bib, misc_html),
    (online_bib, online_html),
    (phdthesis_bib, phdthesis_html),
    (proceedings_bib, proceedings_html),
    (techreport_bib, techreport_html),
    (unpublished_bib, unpublished_html),
])
def test_backend_html(bib, html):
    style = UnsrtStyle()
    backend = HtmlBackend()
    bib_data = parse_string(bib, 'bibtex')
    for formatted_entry in style.format_entries(bib_data.entries.values()):
        render = formatted_entry.text.render(backend)
        print(render)
        assert render.strip() == html.strip()