Repository: streamlink/streamlink
Pull request #565 (2017-02-10 16:22:24)

tests: speed up the cmdline tests
When #453 was merged it added some possible delay in killing the player process, this delay was also experienced in the tests. By mocking the expected return values of `poll()`, the delay can be avoided and the runtime of the tests reduced from around 60 seconds to 6 seconds.


Patch:
diff --git a/CHANGELOG.rst b/CHANGELOG.rst
index 0256e800..42b0f487 100644
--- a/CHANGELOG.rst
+++ b/CHANGELOG.rst
@@ -1,34 +1,3 @@
-streamlink 0.3.2 (2017-02-10)
------------------------------
-0.3.2 release of Streamlink!
-
-A minor bug release of 0.3.2 to fix a few issues with stream providers. 
-
-Thanks to all whom have contributed to this (tiny) release!
-
-::
-
-    Charlie Drage <charlie@charliedrage.com> (3):
-          Update release script again to include sdist
-          Fix underlining issue
-          Fix the CHANGELOG.rst
-    
-    Sven <sven@androd.se> (1):
-          Adding Huomao plugin with possibility for different stream qualities.
-    
-    beardypig <beardypig@users.noreply.github.com> (7):
-          Ensure retries with HLS Streams (#522)
-          utils.l10n: add Country/Language classes, use pycountry is the iso modules are not available
-          plugins.crunchyroll: added option to set the session id to a specific value
-          CI: add pycountry for testing
-          plugins.openrectv: add source quality for openrectv
-          utils.l10n: default to en_US when an invalid locale is set
-          stream.hls: pick a better default stream language
-    
-    intact <intact.devel@gmail.com> (1):
-          Add Rtvs.sk Plugin
-    
-
 streamlink 0.3.1 (2017-02-03)
 -----------------------------
 0.3.1 release of Streamlink
diff --git a/appveyor.yml b/appveyor.yml
index ed6353e1..d4c99ebe 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -45,7 +45,7 @@ install:
   # install dev requirements, for testing, etc.
   - "pip install -r dev-requirements.txt"
   - "pip install pycountry" 
-  - "build.cmd %PYTHON%\\python.exe -m pip install ."
+  - "pip install ."
 
 build: off
 
diff --git a/script/release.sh b/script/release.sh
index b7803cb3..f2c45074 100755
--- a/script/release.sh
+++ b/script/release.sh
@@ -95,7 +95,7 @@ changelog_rst() {
   DATE=$(date +"%Y-%m-%d")
   CHANGELOG=$(cat CHANGELOG.rst)
   HEADER="$CLI $1 ($DATE)"
-  UNDERLINE=$(printf %s "$HEADER" | tr -c '-' '[-*]')
+  UNDERLINE=$(printf %s "$HEADER" | tr -c '-' '[_*]')
   echo -e "$HEADER\n$UNDERLINE\n$CHANGES\n\n$CHANGELOG" >CHANGELOG.rst
   echo "Changes have been written to CHANGELOG.rst"
   cd ..
diff --git a/setup.py b/setup.py
index 39d014ee..c5e86b4d 100644
--- a/setup.py
+++ b/setup.py
@@ -46,7 +46,7 @@ srcdir = join(dirname(abspath(__file__)), "src/")
 sys_path.insert(0, srcdir)
 
 setup(name="streamlink",
-      version="0.3.2",
+      version="0.3.1",
       description="Streamlink is command-line utility that extracts streams "
                   "from various services and pipes them into a video player of "
                   "choice.",
diff --git a/src/streamlink/__init__.py b/src/streamlink/__init__.py
index 9750cc17..2fd383f6 100644
--- a/src/streamlink/__init__.py
+++ b/src/streamlink/__init__.py
@@ -12,7 +12,7 @@ Full documentation is available at https://streamlink.github.io.
 
 
 __title__ = "streamlink"
-__version__ = "0.3.2"
+__version__ = "0.3.1"
 __license__ = "Simplified BSD"
 __author__ = "Streamlink"
 __copyright__ = "Copyright 2016 Streamlink"
diff --git a/src/streamlink/plugins/huomao.py b/src/streamlink/plugins/huomao.py
deleted file mode 100644
index ca5371ff..00000000
--- a/src/streamlink/plugins/huomao.py
+++ /dev/null
@@ -1,97 +0,0 @@
-# NOTE: Since a documented API is nowhere to be found for Huomao; this plugin
-# simply extracts the videos stream_id, stream_url and stream_quality by 
-# scraping the HTML and JS of one of Huomaos mobile webpages. 
-
-# When viewing a stream on huomao.com, the base URL references a room_id. This 
-# room_id is mapped one-to-one to a stream_id which references the actual .flv
-# video. Both stream_id, stream_url and stream_quality can be found in the 
-# HTML and JS source of the mobile_page. Since one stream can occur in many
-# different qualities, we scrape all stream_url and stream_quality occurences
-# and return each option to the user.
-
-import re
-
-from streamlink.plugin import Plugin
-from streamlink.plugin.api import http, validate
-from streamlink.stream import HTTPStream
-
-# URL pattern for recognizing inputed Huomao.tv / Huomao.com URL.
-url_re = re.compile(r"""
-    (http(s)?://)? 
-    (www\.)?
-    huomao
-    (\.tv|\.com)
-    /(?P<room_id>\d+)
-""", re.VERBOSE)
-
-# URL used to retrive the stream_id, stream_url and stream_quality based of
-# a room_id.
-mobile_url = "http://www.huomao.com/mobile/mob_live/{0}"
-
-# Pattern for extracting the stream_id from the mobile_url HTML.
-#
-# Example from HTML:
-#   <input id="html_stream" value="efmrCH" type="hidden">
-stream_id_pattern = re.compile(r'id=\"html_stream\" value=\"(?P<stream_id>\w+)\"')
-
-# Pattern for extracting each stream_url, stream_quality_url and a prettified 
-# stream_quality_name used for quality naming.
-# 
-# Example from HTML: 
-#   "2: 'http://live-ws.huomaotv.cn/live/'+stream+'_720/playlist.m3u8'"
-stream_info_pattern = re.compile(r"""
-    [1-9]:
-    \s+
-    '(?P<stream_url>(?:\w|\.|:|-|/)+)
-    '\+stream\+'
-    (?P<stream_quality_url>_?(?P<stream_quality_name>\d*))
-    /playlist.m3u8'
-""", re.VERBOSE)
-
-# Returns the stream_id contained in the HTML.
-def get_stream_id(self, html):
-    stream_id = stream_id_pattern.search(html)
-    
-    if not stream_id:
-        self.logger.error("Failed to extract stream_id.")
-
-    return stream_id.group("stream_id")
-
-# Returns a list of each stream_url, stream_quality_url and stream_quality_name
-# occurence in the JS.
-def get_stream_info(self, html):
-    stream_info = stream_info_pattern.findall(html.text)
-
-    if not stream_info:
-        self.logger.error("Failed to extract stream_info.")
-
-    # Rename the "" quality to "source" by transforming the tuples to a
-    # list and reassigning.
-    stream_info_list = []
-    for info in stream_info:
-        if not info[2]:
-            stream_info_list.append([info[0], info[1], "source"])
-        else:
-            stream_info_list.append(list(info))
-
-    return stream_info_list
-
-class Huomao(Plugin):
-    @classmethod
-    def can_handle_url(self, url):
-        return url_re.match(url)
-
-    def _get_streams(self):
-        room_id = url_re.search(self.url).group("room_id")
-        html = http.get(mobile_url.format(room_id))
-        stream_id = get_stream_id(self, html.text)
-        stream_info = get_stream_info(self, html)
-
-        streams = {}
-        for info in stream_info:
-            streams[info[2]] = HTTPStream(self.session, 
-                info[0] + stream_id + info[1] + ".flv")
-
-        return streams
-
-__plugin__ = Huomao
diff --git a/src/streamlink_cli/output.py b/src/streamlink_cli/output.py
index 15db472e..f86a4933 100644
--- a/src/streamlink_cli/output.py
+++ b/src/streamlink_cli/output.py
@@ -97,8 +97,7 @@ class PlayerOutput(Output):
     @property
     def running(self):
         sleep(0.5)
-        self.player.poll()
-        return self.player.returncode is None
+        return self.player.poll() is None
 
     def _create_arguments(self):
         if self.namedpipe:


Test patch:
diff --git a/tests/test_cmdline.py b/tests/test_cmdline.py
index c2972877..21e40574 100644
--- a/tests/test_cmdline.py
+++ b/tests/test_cmdline.py
@@ -32,8 +32,14 @@ class TestCommandLineInvocation(unittest.TestCase):
     @patch('sys.argv')
     def _test_args(self, args, commandline, mock_argv, mock_popen, mock_setup_streamlink, passthrough=False):
         mock_argv.__getitem__.side_effect = lambda x: args[x]
-        mock_popen().returncode = None
-        mock_popen().poll.return_value = None
+
+        def side_effect(results):
+            def fn(*args):
+                result = results.pop(0)
+                return result
+            return fn
+
+        mock_popen().poll.side_effect = side_effect([None, 0])
 
         streamlink_cli.main.main()
         mock_setup_streamlink.assert_called_with()