Skip to content

Commit

Permalink
tests: start a local HTTP server instead of relying on GitHub
Browse files Browse the repository at this point in the history
This allows us to run the whole test suite without any kind of Internet
access.
  • Loading branch information
sbraz committed May 7, 2021
1 parent b4c4a92 commit 2e5891b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ test = pytest

[tool:pytest]
addopts = -vv -r a
markers = internet: tests that require Internet access

[bdist_wheel]
universal = 1
26 changes: 22 additions & 4 deletions tests/test_pymediainfo.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
# pylint: disable=missing-module-docstring, missing-class-docstring, missing-function-docstring,
# pylint: disable=protected-access

import functools
import http.server
import json
import os
import pathlib
import pickle
import sys
import tempfile
import threading
import unittest
Expand Down Expand Up @@ -159,14 +162,29 @@ def test_parse_unicode_file(self):
self.assertEqual(len(self.media_info.tracks), 1)


@pytest.mark.internet
@pytest.mark.skipif(
sys.version_info < (3, 7),
reason="SimpleHTTPRequestHandler's 'directory' argument was added in Python 3.7",
)
class MediaInfoURLTest(unittest.TestCase):
def setUp(self):
url = "https://github.com/sbraz/pymediainfo/raw/v5.0/tests/data/sample.mkv"
self.media_info = MediaInfo.parse(url)
HandlerClass = functools.partial( # pylint: disable=invalid-name
http.server.SimpleHTTPRequestHandler,
directory=data_dir,
)
# Pick a random port so that parallel tests (e.g. via 'tox -p') do not clash
self.httpd = http.server.HTTPServer(("", 0), HandlerClass)
port = self.httpd.socket.getsockname()[1]
self.url = f"http://127.0.0.1:{port}/sample.mkv"
threading.Thread(target=self.httpd.serve_forever).start()

def tearDown(self):
self.httpd.shutdown()
self.httpd.server_close()

def test_parse_url(self):
self.assertEqual(len(self.media_info.tracks), 3)
media_info = MediaInfo.parse(self.url)
self.assertEqual(len(media_info.tracks), 3)


class MediaInfoPathlibTest(unittest.TestCase):
Expand Down

1 comment on commit 2e5891b

@sbraz
Copy link
Owner Author

@sbraz sbraz commented on 2e5891b May 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Vascom @jfrankenau @ryantm @lgbaldoni Now you won't have to skip test_parse_url when the next version is released 😃. Please note that it does requires libmediainfo built with curl support.

Please sign in to comment.