Skip to content

Commit 61edce5

Browse files
committed
test: convert unittest style tests to pytest test functions
1 parent 00c971e commit 61edce5

File tree

1 file changed

+38
-39
lines changed

1 file changed

+38
-39
lines changed

tests/test_tika.py

Lines changed: 38 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,58 +15,57 @@
1515
# See the License for the specific language governing permissions and
1616
# limitations under the License.
1717

18-
import os
19-
import unittest
18+
from pathlib import Path
2019
from http import HTTPStatus
2120

2221
import tika.parser
2322
import tika.tika
2423

2524

26-
class CreateTest(unittest.TestCase):
27-
"""test for file types"""
25+
TEST_FILE_PATH = Path(__file__).parent / "files" / "rwservlet.pdf"
2826

29-
def test_remote_pdf(self):
30-
"""parse remote PDF"""
31-
self.assertTrue(tika.parser.from_file(
32-
'https://upload.wikimedia.org/wikipedia/commons/4/42/Article_feedback_flow_B_-_Thank_editors.pdf'))
3327

34-
def test_remote_html(self):
35-
"""parse remote HTML"""
36-
self.assertTrue(tika.parser.from_file('http://neverssl.com/index.html'))
28+
def test_remote_pdf():
29+
"""parse remote PDF"""
30+
assert tika.parser.from_file(
31+
"https://upload.wikimedia.org/wikipedia/commons/4/42/Article_feedback_flow_B_-_Thank_editors.pdf")
3732

38-
def test_remote_mp3(self):
39-
"""parse remote mp3"""
40-
self.assertTrue(tika.parser.from_file(
41-
'https://archive.org/download/Ainst-Spaceshipdemo.mp3/Ainst-Spaceshipdemo.mp3'))
4233

43-
def test_remote_jpg(self):
44-
"""parse remote jpg"""
45-
self.assertTrue(tika.parser.from_file(
46-
'https://upload.wikimedia.org/wikipedia/commons/b/b7/X_logo.jpg'))
34+
def test_remote_html():
35+
"""parse remote HTML"""
36+
assert tika.parser.from_file("http://neverssl.com/index.html")
4737

48-
def test_local_binary(self):
49-
"""parse file binary"""
50-
file = os.path.join(os.path.dirname(__file__), 'files', 'rwservlet.pdf')
51-
with open(file, 'rb') as file_obj:
52-
self.assertTrue(tika.parser.from_file(file_obj))
5338

54-
def test_local_buffer(self):
55-
response = tika.parser.from_buffer('Good evening, Dave')
56-
self.assertEqual(response['status'], HTTPStatus.OK)
39+
def test_remote_mp3():
40+
"""parse remote mp3"""
41+
assert tika.parser.from_file(
42+
"https://archive.org/download/Ainst-Spaceshipdemo.mp3/Ainst-Spaceshipdemo.mp3")
5743

58-
def test_local_path(self):
59-
"""parse file path"""
60-
file = os.path.join(os.path.dirname(__file__), 'files', 'rwservlet.pdf')
61-
self.assertTrue(tika.parser.from_file(file))
6244

63-
def test_kill_server(self):
64-
"""parse some file then kills server"""
65-
file = os.path.join(os.path.dirname(__file__), 'files', 'rwservlet.pdf')
66-
with open(file, 'rb') as file_obj:
67-
tika.parser.from_file(file_obj)
68-
self.assertIsNone(tika.tika.killServer())
45+
def test_remote_jpg():
46+
"""parse remote jpg"""
47+
assert tika.parser.from_file(
48+
"https://upload.wikimedia.org/wikipedia/commons/b/b7/X_logo.jpg")
6949

7050

71-
if __name__ == '__main__':
72-
unittest.main()
51+
def test_local_binary():
52+
"""parse file binary"""
53+
with open(TEST_FILE_PATH, "rb") as file_obj:
54+
assert tika.parser.from_file(file_obj)
55+
56+
57+
def test_local_buffer():
58+
response = tika.parser.from_buffer("Good evening, Dave")
59+
assert response["status"] == HTTPStatus.OK
60+
61+
62+
def test_local_path():
63+
"""parse file path"""
64+
assert tika.parser.from_file(TEST_FILE_PATH)
65+
66+
67+
def test_kill_server():
68+
"""parse some file then kills server"""
69+
with open(TEST_FILE_PATH, "rb") as file_obj:
70+
tika.parser.from_file(file_obj)
71+
assert tika.tika.killServer() is None

0 commit comments

Comments
 (0)