Bug 1471920 - [mozversion] Convert test_filelist to pytest and support Python 3; r?raphael,ahal draft
authorDave Hunt <dhunt@mozilla.com>
Sat, 28 Jul 2018 14:39:21 +0100
changeset 823798 d5a69e6fae5b57178c7b4214f0066c67cf92d996
parent 823465 87bcafe428a4ad6017e59b915581ae00aa863407
push id117785
push userbmo:dave.hunt@gmail.com
push dateSat, 28 Jul 2018 14:12:52 +0000
reviewersraphael, ahal
bugs1471920
milestone63.0a1
Bug 1471920 - [mozversion] Convert test_filelist to pytest and support Python 3; r?raphael,ahal MozReview-Commit-ID: CPW3wGOZ9q4
testing/mozbase/mozhttpd/tests/filelisting.py
testing/mozbase/mozhttpd/tests/manifest.ini
--- a/testing/mozbase/mozhttpd/tests/filelisting.py
+++ b/testing/mozbase/mozhttpd/tests/filelisting.py
@@ -2,46 +2,35 @@
 
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this file,
 # You can obtain one at http://mozilla.org/MPL/2.0/.
 
 from __future__ import absolute_import
 
 import mozhttpd
-import urllib2
 import os
-import unittest
 import re
 
 import mozunit
+import pytest
+from six.moves.urllib.request import urlopen
 
 here = os.path.dirname(os.path.abspath(__file__))
 
 
-class FileListingTest(unittest.TestCase):
-
-    def check_filelisting(self, path=''):
-        filelist = os.listdir(here)
-
-        httpd = mozhttpd.MozHttpd(port=0, docroot=here)
-        httpd.start(block=False)
-        f = urllib2.urlopen("http://%s:%s/%s" % ('127.0.0.1', httpd.httpd.server_port, path))
-        for line in f.readlines():
-            webline = re.sub('\<[a-zA-Z0-9\-\_\.\=\"\'\/\\\%\!\@\#\$\^\&\*\(\) ]*\>',
-                             '', line.strip('\n')).strip('/').strip().strip('@')
+@pytest.fixture(name='dirlist', params=['', '?foo=bar&fleem=&foo=fleem'])
+def fixture_dirlist(request):
+    httpd = mozhttpd.MozHttpd(port=0, docroot=here)
+    httpd.start(block=False)
+    f = urlopen('http://%s:%s/%s' % ('127.0.0.1', httpd.httpd.server_port, request.param))
+    pattern = b'<a.*>(.*)<\/a>'
+    dirlist = filter(lambda x: re.search(pattern, x), f.readlines())
+    yield list(map(lambda x: re.search(pattern, x).group(1).decode(), dirlist))
+    httpd.stop()
 
-            if webline and not webline.startswith("Directory listing for"):
-                self.assertTrue(webline in filelist,
-                                "File %s in dir listing corresponds to a file" % webline)
-                filelist.remove(webline)
-        self.assertFalse(
-            filelist, "Should have no items in filelist (%s) unaccounted for" % filelist)
 
-    def test_filelist(self):
-        self.check_filelisting()
-
-    def test_filelist_params(self):
-        self.check_filelisting('?foo=bar&fleem=&foo=fleem')
+def test_filelist(dirlist):
+    assert sorted(os.listdir(here)) == sorted(dirlist)
 
 
 if __name__ == '__main__':
     mozunit.main()
--- a/testing/mozbase/mozhttpd/tests/manifest.ini
+++ b/testing/mozbase/mozhttpd/tests/manifest.ini
@@ -1,10 +1,9 @@
 [DEFAULT]
 subsuite = mozbase, os == "linux"
 [api.py]
 skip-if = python == 3
 [baseurl.py]
 [basic.py]
 [filelisting.py]
-skip-if = python == 3
 [paths.py]
 [requestlog.py]