|
15 | 15 | # See the License for the specific language governing permissions and |
16 | 16 | # limitations under the License. |
17 | 17 |
|
18 | | -import os |
19 | | -import unittest |
| 18 | +from pathlib import Path |
20 | 19 | from http import HTTPStatus |
21 | 20 |
|
22 | 21 | import tika.parser |
23 | 22 | import tika.tika |
24 | 23 |
|
25 | 24 |
|
26 | | -class CreateTest(unittest.TestCase): |
27 | | - """test for file types""" |
| 25 | +TEST_FILE_PATH = Path(__file__).parent / "files" / "rwservlet.pdf" |
28 | 26 |
|
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')) |
33 | 27 |
|
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") |
37 | 32 |
|
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')) |
42 | 33 |
|
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") |
47 | 37 |
|
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)) |
53 | 38 |
|
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") |
57 | 43 |
|
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)) |
62 | 44 |
|
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") |
69 | 49 |
|
70 | 50 |
|
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