--- a/testing/mozbase/manifestparser/tests/test_chunking.py
+++ b/testing/mozbase/manifestparser/tests/test_chunking.py
@@ -1,15 +1,17 @@
#!/usr/bin/env python
from itertools import chain
from unittest import TestCase
import os
import random
+import mozunit
+
from manifestparser.filters import (
chunk_by_dir,
chunk_by_runtime,
chunk_by_slice,
)
here = os.path.dirname(os.path.abspath(__file__))
@@ -295,8 +297,12 @@ class ChunkByRuntime(TestCase):
'b/d': 5,
'b/d/e': 6,
'c': 8,
'c/d/e/f/g/h/i/j/k/l': 5,
'c/d/e/f/g/i/j/k/l/m/n': 2,
'c/e': 1,
}
self.run_all_combos(dirs)
+
+
+if __name__ == '__main__':
+ mozunit.main()
--- a/testing/mozbase/manifestparser/tests/test_convert_directory.py
+++ b/testing/mozbase/manifestparser/tests/test_convert_directory.py
@@ -4,16 +4,18 @@
# 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/.
import os
import shutil
import tempfile
import unittest
+import mozunit
+
from manifestparser import convert
from manifestparser import ManifestParser
here = os.path.dirname(os.path.abspath(__file__))
# In some cases tempfile.mkdtemp() may returns a path which contains
# symlinks. Some tests here will then break, as the manifestparser.convert
# function returns paths that does not contains symlinks.
@@ -173,9 +175,9 @@ class TestDirectoryConversion(unittest.T
'secret door')
# clean up:
shutil.rmtree(tempdir)
shutil.rmtree(newtempdir)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/manifestparser/tests/test_convert_symlinks.py
+++ b/testing/mozbase/manifestparser/tests/test_convert_symlinks.py
@@ -4,16 +4,18 @@
# 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/.
import os
import shutil
import tempfile
import unittest
+import mozunit
+
from manifestparser import convert, ManifestParser
class TestSymlinkConversion(unittest.TestCase):
"""
test conversion of a directory tree with symlinks to a manifest structure
"""
@@ -131,9 +133,9 @@ class TestSymlinkConversion(unittest.Tes
for f in files:
data.append(f)
ManifestParser._walk_directories([workspace], callback)
self.assertEqual(sorted(data), ['f1.txt', 'f2.txt'])
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/manifestparser/tests/test_default_overrides.py
+++ b/testing/mozbase/manifestparser/tests/test_default_overrides.py
@@ -1,16 +1,19 @@
#!/usr/bin/env python
# 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/.
import os
import unittest
+
+import mozunit
+
from manifestparser import ManifestParser
from manifestparser import combine_fields
here = os.path.dirname(os.path.abspath(__file__))
class TestDefaultSkipif(unittest.TestCase):
"""Tests applying a skip-if condition in [DEFAULT] and || with the value for the test"""
@@ -107,9 +110,9 @@ class TestSubsuiteDefaults(unittest.Test
}
defaults = parser.manifest_defaults[manifest]
for test in parser.tests:
value = combine_fields(defaults, test)
self.assertEqual(expected_subsuites[value['name']],
value['subsuite'])
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/manifestparser/tests/test_expressionparser.py
+++ b/testing/mozbase/manifestparser/tests/test_expressionparser.py
@@ -1,11 +1,14 @@
#!/usr/bin/env python
import unittest
+
+import mozunit
+
from manifestparser import parse
class ExpressionParserTest(unittest.TestCase):
"""Test the conditional expression parser."""
def test_basic(self):
@@ -144,9 +147,9 @@ class ExpressionParserTest(unittest.Test
self.assertTrue(parse("true && 2 >= 1"))
self.assertTrue(parse("!(1 >= 5)"))
self.assertTrue(parse("'def' >= 'abc'"))
self.assertTrue(parse("1 >= 1"))
self.assertTrue(parse("'abc' >= 'abc'"))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/manifestparser/tests/test_filters.py
+++ b/testing/mozbase/manifestparser/tests/test_filters.py
@@ -1,15 +1,17 @@
#!/usr/bin/env python
# flake8: noqa
from copy import deepcopy
import os
import unittest
+import mozunit
+
from manifestparser.filters import (
subsuite,
tags,
skip_if,
run_if,
fail_if,
enabled,
filterlist,
@@ -175,8 +177,12 @@ class BuiltinFilters(unittest.TestCase):
tests = deepcopy(self.tests)
tests = list(ftags1(tests, {}))
self.assertEquals(len(tests), 0)
tests = deepcopy(self.tests)
tests = list(ftags2(tests, {}))
self.assertEquals(len(tests), 1)
self.assertIn(self.tests[7], tests)
+
+
+if __name__ == '__main__':
+ mozunit.main()
--- a/testing/mozbase/manifestparser/tests/test_manifestparser.py
+++ b/testing/mozbase/manifestparser/tests/test_manifestparser.py
@@ -3,18 +3,21 @@
# 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/.
import os
import shutil
import tempfile
import unittest
+from StringIO import StringIO
+
+import mozunit
+
from manifestparser import ManifestParser
-from StringIO import StringIO
here = os.path.dirname(os.path.abspath(__file__))
class TestManifestParser(unittest.TestCase):
"""
Test the manifest parser
@@ -317,9 +320,9 @@ yellow = submarine""" # noqa
parser = ManifestParser()
manifest = os.path.join(here, 'no-tests.ini')
parser.read(manifest)
self.assertEqual(len(parser.tests), 0)
self.assertTrue(len(parser.manifests()) == 1)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/manifestparser/tests/test_read_ini.py
+++ b/testing/mozbase/manifestparser/tests/test_read_ini.py
@@ -10,16 +10,18 @@ is the default:
http://docs.python.org/2/library/configparser.html
"""
import unittest
from manifestparser import read_ini
from ConfigParser import ConfigParser
from StringIO import StringIO
+import mozunit
+
class IniParserTest(unittest.TestCase):
def test_inline_comments(self):
"""
We have no inline comments; so we're testing to ensure we don't:
https://bugzilla.mozilla.org/show_bug.cgi?id=855288
"""
@@ -62,9 +64,9 @@ kittens = true # This test requires kitt
buffer.seek(0)
parser = ConfigParser()
parser.readfp(buffer)
control = parser.get('test_felinicity.py', 'kittens')
self.assertNotEqual(result, control)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/manifestparser/tests/test_testmanifest.py
+++ b/testing/mozbase/manifestparser/tests/test_testmanifest.py
@@ -1,15 +1,17 @@
#!/usr/bin/env python
import os
import shutil
import tempfile
import unittest
+import mozunit
+
from manifestparser import TestManifest, ParseError
from manifestparser.filters import subsuite
here = os.path.dirname(os.path.abspath(__file__))
class TestTestManifest(unittest.TestCase):
"""Test the Test Manifest"""
@@ -114,9 +116,9 @@ class TestTestManifest(unittest.TestCase
self.assertEqual(len(none_manifest.test_paths()), 0)
self.assertEqual(len(none_manifest.active_tests()), 0)
empty_manifest = TestManifest(manifests=[], strict=False)
self.assertEqual(len(empty_manifest.test_paths()), 0)
self.assertEqual(len(empty_manifest.active_tests()), 0)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozcrash/tests/test.py
+++ b/testing/mozbase/mozcrash/tests/test.py
@@ -7,16 +7,19 @@
import os
import unittest
import subprocess
import tempfile
import shutil
import urlparse
import zipfile
import StringIO
+
+import mozunit
+
import mozcrash
import mozhttpd
import mozlog.unstructured as mozlog
# Make logs go away
log = mozlog.getLogger("mozcrash", handler=mozlog.FileHandler(os.devnull))
@@ -233,9 +236,9 @@ class TestJavaException(unittest.TestCas
Test for an exception which should not be caught
"""
passable_log = list(self.test_log)
passable_log[0] = "01-30 20:15:41.937 E/GeckoAppShell( 1703):" \
" >>> NOT-SO-BAD EXCEPTION FROM THREAD 9 (\"GeckoBackgroundThread\")"
self.assert_(not mozcrash.check_for_java_exception(passable_log, quiet=True))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozdevice/tests/droidsut_launch.py
+++ b/testing/mozbase/mozdevice/tests/droidsut_launch.py
@@ -1,13 +1,15 @@
from sut import MockAgent
import mozdevice
import logging
import unittest
+import mozunit
+
class LaunchTest(unittest.TestCase):
def test_nouserserial(self):
a = MockAgent(self, commands=[("ps",
"10029 549 com.android.launcher\n"
"10066 1198 com.twitter.android"),
("info sutuserinfo", ""),
@@ -28,9 +30,9 @@ class LaunchTest(unittest.TestCase):
"org.mozilla.fennec/org.mozilla.gecko.BrowserApp -a "
"android.intent.action.VIEW",
"OK\nreturn code [0]")])
d = mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=logging.DEBUG)
d.launchFennec("org.mozilla.fennec")
a.wait()
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozdevice/tests/sut_app.py
+++ b/testing/mozbase/mozdevice/tests/sut_app.py
@@ -1,20 +1,23 @@
#!/usr/bin/env python
import mozdevice
import logging
import unittest
+
+import mozunit
+
from sut import MockAgent
class TestApp(unittest.TestCase):
def test_getAppRoot(self):
command = [("getapproot org.mozilla.firefox",
"/data/data/org.mozilla.firefox")]
m = MockAgent(self, commands=command)
d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=logging.DEBUG)
self.assertEqual(command[0][1], d.getAppRoot('org.mozilla.firefox'))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozdevice/tests/sut_basic.py
+++ b/testing/mozbase/mozdevice/tests/sut_basic.py
@@ -1,13 +1,15 @@
from sut import MockAgent
import mozdevice
import logging
import unittest
+import mozunit
+
class BasicTest(unittest.TestCase):
def test_init(self):
"""Tests DeviceManager initialization."""
a = MockAgent(self)
mozdevice.DroidSUT("127.0.0.1", port=a.port, logLevel=logging.DEBUG)
@@ -65,9 +67,9 @@ class BasicTest(unittest.TestCase):
except mozdevice.DMError:
exceptionThrown = True
expectedException = (retcode != 0)
self.assertEqual(exceptionThrown, expectedException)
a.wait()
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozdevice/tests/sut_chmod.py
+++ b/testing/mozbase/mozdevice/tests/sut_chmod.py
@@ -1,12 +1,15 @@
#!/usr/bin/env python
import mozdevice
import logging
import unittest
+
+import mozunit
+
from sut import MockAgent
class TestChmod(unittest.TestCase):
def test_chmod(self):
command = [('chmod /mnt/sdcard/test',
@@ -14,9 +17,9 @@ class TestChmod(unittest.TestCase):
' <empty>\n'
'chmod /storage/emulated/legacy/Test ok\n')]
m = MockAgent(self, commands=command)
d = mozdevice.DroidSUT('127.0.0.1', port=m.port, logLevel=logging.DEBUG)
self.assertEqual(None, d.chmodDir('/mnt/sdcard/test'))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozdevice/tests/sut_copytree.py
+++ b/testing/mozbase/mozdevice/tests/sut_copytree.py
@@ -3,16 +3,19 @@
# 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/.
import mozdevice
import logging
import unittest
+
+import mozunit
+
from sut import MockAgent
class CopyTreeTest(unittest.TestCase):
def test_copyFile(self):
commands = [('dd if=/mnt/sdcard/tests/test.txt of=/mnt/sdcard/tests/test2.txt', ''),
('isdir /mnt/sdcard/tests', 'TRUE'),
@@ -59,9 +62,9 @@ class CopyTreeTest(unittest.TestCase):
self.assertTrue(d.dirExists('/mnt/sdcard/tests/foo/bar'))
self.assertEqual(None, d.copyTree('/mnt/sdcard/tests/foo',
'/mnt/sdcard/tests/foo2'))
expected = (commands[4][1].strip()).split('\n')
self.assertEqual(expected, d.listFiles('/mnt/sdcard/tests'))
self.assertTrue(d.fileExists('/mnt/sdcard/tests/foo2/bar'))
if __name__ == "__main__":
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozdevice/tests/sut_fileExists.py
+++ b/testing/mozbase/mozdevice/tests/sut_fileExists.py
@@ -1,11 +1,14 @@
-from sut import MockAgent
+import unittest
+
+import mozunit
+
import mozdevice
-import unittest
+from sut import MockAgent
class FileExistsTest(unittest.TestCase):
commands = [('isdir /', 'TRUE'),
('cd /', ''),
('ls', 'init')]
@@ -21,9 +24,9 @@ class FileExistsTest(unittest.TestCase):
self.assertFalse(d.fileExists('/doesNotExist'))
def test_onRegularFile(self):
a = MockAgent(self, commands=self.commands)
d = mozdevice.DroidSUT("127.0.0.1", port=a.port)
self.assertTrue(d.fileExists('/init'))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozdevice/tests/sut_fileMethods.py
+++ b/testing/mozbase/mozdevice/tests/sut_fileMethods.py
@@ -1,16 +1,19 @@
#!/usr/bin/env python
import hashlib
import mozdevice
import logging
import shutil
import tempfile
import unittest
+
+import mozunit
+
from sut import MockAgent
class TestFileMethods(unittest.TestCase):
""" Class to test misc file methods """
content = "What is the answer to the life, universe and everything? 42"
h = hashlib.md5()
@@ -64,9 +67,9 @@ class TestFileMethods(unittest.TestCase)
m = MockAgent(self, commands=commands)
d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=logging.DEBUG)
self.assertEqual(None, d.getDirectory("/mnt/sdcard", tmpdir))
# Cleanup
shutil.rmtree(tmpdir)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozdevice/tests/sut_info.py
+++ b/testing/mozbase/mozdevice/tests/sut_info.py
@@ -1,13 +1,16 @@
#!/usr/bin/env python
import mozdevice
import logging
import re
import unittest
+
+import mozunit
+
from sut import MockAgent
class TestGetInfo(unittest.TestCase):
commands = {'os': ('info os', 'JDQ39'),
'id': ('info id', '11:22:33:44:55:66'),
'uptime': ('info uptime', '0 days 0 hours 7 minutes 0 seconds 0 ms'),
@@ -41,9 +44,9 @@ class TestGetInfo(unittest.TestCase):
expected = re.sub(r'\ +', ' ', self.commands[directive][1]).split('\n')
# Account for slightly different return format for 'process'
if directive is 'process':
expected = [[x] for x in expected]
self.assertEqual(d.getInfo(directive=directive)[directive], expected)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozdevice/tests/sut_ip.py
+++ b/testing/mozbase/mozdevice/tests/sut_ip.py
@@ -1,12 +1,15 @@
#!/usr/bin/env python
import mozdevice
import logging
import unittest
+
+import mozunit
+
from sut import MockAgent
class TestGetIP(unittest.TestCase):
""" class to test IP methods """
commands = [('exec ifconfig eth0', 'eth0: ip 192.168.0.1 '
'mask 255.255.255.0 flags [up broadcast running multicast]\n'
@@ -29,9 +32,9 @@ class TestGetIP(unittest.TestCase):
self.assertEqual('10.1.39.126', d.getIP(interfaces=['wlan0']))
def test_getIP_error(self):
m = MockAgent(self, commands=[self.commands[2]])
d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=logging.DEBUG)
self.assertRaises(mozdevice.DMError, d.getIP, interfaces=['fake0'])
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozdevice/tests/sut_kill.py
+++ b/testing/mozbase/mozdevice/tests/sut_kill.py
@@ -1,13 +1,16 @@
#!/usr/bin/env python
import mozdevice
import logging
import unittest
+
+import mozunit
+
from sut import MockAgent
class TestKill(unittest.TestCase):
def test_killprocess(self):
commands = [("ps", "1000 1486 com.android.settings\n"
"10016 420 com.android.location.fused\n"
@@ -16,9 +19,9 @@ class TestKill(unittest.TestCase):
"Successfully killed com.android.settings\n")]
m = MockAgent(self, commands=commands)
d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=logging.DEBUG)
# No error raised means success
self.assertEqual(None, d.killProcess("com.android.settings"))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozdevice/tests/sut_list.py
+++ b/testing/mozbase/mozdevice/tests/sut_list.py
@@ -1,12 +1,15 @@
#!/usr/bin/env python
import mozdevice
import logging
import unittest
+
+import mozunit
+
from sut import MockAgent
class TestListFiles(unittest.TestCase):
commands = [("isdir /mnt/sdcard", "TRUE"),
("cd /mnt/sdcard", ""),
("ls", "Android\nMusic\nPodcasts\nRingtones\nAlarms\n"
"Notifications\nPictures\nMovies\nDownload\nDCIM\n")]
@@ -14,9 +17,9 @@ class TestListFiles(unittest.TestCase):
def test_listFiles(self):
m = MockAgent(self, commands=self.commands)
d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=logging.DEBUG)
expected = (self.commands[2][1].strip()).split("\n")
self.assertEqual(expected, d.listFiles("/mnt/sdcard"))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozdevice/tests/sut_logcat.py
+++ b/testing/mozbase/mozdevice/tests/sut_logcat.py
@@ -1,13 +1,16 @@
#!/usr/bin/env python
import mozdevice
import logging
import unittest
+
+import mozunit
+
from sut import MockAgent
class TestLogCat(unittest.TestCase):
""" Class to test methods associated with logcat """
def test_getLogcat(self):
@@ -44,9 +47,9 @@ class TestLogCat(unittest.TestCase):
commands = [("execsu /system/bin/logcat -c", "return code [0]")]
m = MockAgent(self, commands=commands)
d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=logging.DEBUG)
# No error raised means success
self.assertEqual(None, d.recordLogcat())
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozdevice/tests/sut_mkdir.py
+++ b/testing/mozbase/mozdevice/tests/sut_mkdir.py
@@ -1,14 +1,17 @@
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
import mozdevice
import logging
import unittest
+
+import mozunit
+
from sut import MockAgent
class MkDirsTest(unittest.TestCase):
def test_mkdirs(self):
subTests = [{'cmds': [('isdir /mnt/sdcard/baz/boop', 'FALSE'),
('info os', 'android'),
@@ -70,9 +73,9 @@ class MkDirsTest(unittest.TestCase):
d = mozdevice.DroidSUT('127.0.0.1', port=a.port,
logLevel=logging.DEBUG)
d.mkDirs('/foo')
a.wait()
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozdevice/tests/sut_movetree.py
+++ b/testing/mozbase/mozdevice/tests/sut_movetree.py
@@ -3,16 +3,19 @@
# 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/.
import mozdevice
import logging
import unittest
+
+import mozunit
+
from sut import MockAgent
class MoveTreeTest(unittest.TestCase):
def test_moveFile(self):
commands = [('mv /mnt/sdcard/tests/test.txt /mnt/sdcard/tests/test1.txt', ''),
('isdir /mnt/sdcard/tests', 'TRUE'),
@@ -57,9 +60,9 @@ class MoveTreeTest(unittest.TestCase):
self.assertTrue(d.dirExists('/mnt/sdcard/tests/foo/bar'))
self.assertEqual(None, d.moveTree('/mnt/sdcard/tests/foo',
'/mnt/sdcard/tests/foo2'))
self.assertTrue(d.fileExists('/mnt/sdcard/tests/foo2'))
self.assertTrue(d.fileExists('/mnt/sdcard/tests/foo2/bar'))
if __name__ == "__main__":
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozdevice/tests/sut_ps.py
+++ b/testing/mozbase/mozdevice/tests/sut_ps.py
@@ -1,12 +1,14 @@
from sut import MockAgent
import mozdevice
import unittest
+import mozunit
+
class PsTest(unittest.TestCase):
pscommands = [('ps',
"10029 549 com.android.launcher\n"
"10066 1198 com.twitter.android")]
bad_pscommands = [('ps',
@@ -42,9 +44,9 @@ class PsTest(unittest.TestCase):
for i in [('com.android.launcher', 549),
('com.fennec.android', None)]:
a = MockAgent(self, commands=self.pscommands)
d = mozdevice.DroidSUT("127.0.0.1", port=a.port)
self.assertEqual(d.processExist(i[0]), i[1])
a.wait()
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozdevice/tests/sut_pull.py
+++ b/testing/mozbase/mozdevice/tests/sut_pull.py
@@ -1,13 +1,15 @@
from sut import MockAgent
import mozdevice
import logging
import unittest
+import mozunit
+
class PullTest(unittest.TestCase):
def test_pull_success(self):
for count in [1, 4, 1024, 2048]:
cheeseburgers = ""
for i in range(count):
cheeseburgers += "cheeseburgers"
@@ -39,9 +41,9 @@ class PullTest(unittest.TestCase):
exceptionThrown = False
try:
d.pullFile("/mnt/sdcard/cheeseburgers")
except mozdevice.DMError:
exceptionThrown = True
self.assertTrue(exceptionThrown)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozdevice/tests/sut_push.py
+++ b/testing/mozbase/mozdevice/tests/sut_push.py
@@ -2,16 +2,18 @@ from sut import MockAgent
import mozfile
import mozdevice
import logging
import unittest
import hashlib
import tempfile
import os
+import mozunit
+
class PushTest(unittest.TestCase):
def test_push(self):
pushfile = "1234ABCD"
mdsum = hashlib.md5()
mdsum.update(pushfile)
expectedResponse = mdsum.hexdigest()
@@ -80,9 +82,9 @@ class PushTest(unittest.TestCase):
exceptionThrown = True
self.assertEqual(exceptionThrown, subTest['expectException'])
a.wait()
# FIXME: delete directory when done
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozdevice/tests/sut_remove.py
+++ b/testing/mozbase/mozdevice/tests/sut_remove.py
@@ -1,12 +1,15 @@
#!/usr/bin/env python
import mozdevice
import logging
import unittest
+
+import mozunit
+
from sut import MockAgent
class TestRemove(unittest.TestCase):
def test_removeDir(self):
commands = [("isdir /mnt/sdcard/test", "TRUE"),
("rmdr /mnt/sdcard/test", "Deleting file(s) from "
@@ -16,9 +19,9 @@ class TestRemove(unittest.TestCase):
"/storage/emulated/legacy/Moztest\n")]
m = MockAgent(self, commands=commands)
d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=logging.DEBUG)
# No error implies we're all good
self.assertEqual(None, d.removeDir("/mnt/sdcard/test"))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozdevice/tests/sut_time.py
+++ b/testing/mozbase/mozdevice/tests/sut_time.py
@@ -1,18 +1,21 @@
#!/usr/bin/env python
import mozdevice
import logging
import unittest
+
+import mozunit
+
from sut import MockAgent
class TestGetCurrentTime(unittest.TestCase):
def test_getCurrentTime(self):
command = [('clok', '1349980200')]
m = MockAgent(self, commands=command)
d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=logging.DEBUG)
self.assertEqual(d.getCurrentTime(), int(command[0][1]))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozdevice/tests/sut_unpackfile.py
+++ b/testing/mozbase/mozdevice/tests/sut_unpackfile.py
@@ -1,13 +1,16 @@
#!/usr/bin/env python
import mozdevice
import logging
import unittest
+
+import mozunit
+
from sut import MockAgent
class TestUnpack(unittest.TestCase):
def test_unpackFile(self):
commands = [("unzp /data/test/sample.zip /data/test/",
@@ -15,9 +18,9 @@ class TestUnpack(unittest.TestCase):
"1 of 1 successfully extracted\n")]
m = MockAgent(self, commands=commands)
d = mozdevice.DroidSUT("127.0.0.1", port=m.port, logLevel=logging.DEBUG)
# No error being thrown imples all is well
self.assertEqual(None, d.unpackFile("/data/test/sample.zip",
"/data/test/"))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozfile/tests/test_extract.py
+++ b/testing/mozbase/mozfile/tests/test_extract.py
@@ -2,16 +2,18 @@
import os
import shutil
import tarfile
import tempfile
import unittest
import zipfile
+import mozunit
+
import mozfile
import stubs
class TestExtract(unittest.TestCase):
"""test extracting archives"""
@@ -147,8 +149,12 @@ class TestExtract(unittest.TestCase):
archive.write(os.path.join(tempdir, *path), arcname=os.path.join(*path))
except:
os.remove(filename)
raise
finally:
shutil.rmtree(tempdir)
archive.close()
return filename
+
+
+if __name__ == '__main__':
+ mozunit.main()
--- a/testing/mozbase/mozfile/tests/test_load.py
+++ b/testing/mozbase/mozfile/tests/test_load.py
@@ -3,16 +3,19 @@
"""
tests for mozfile.load
"""
import mozhttpd
import os
import tempfile
import unittest
+
+import mozunit
+
from mozfile import load
class TestLoad(unittest.TestCase):
"""test the load function"""
def test_http(self):
"""test with mozhttpd and a http:// URL"""
@@ -54,9 +57,9 @@ class TestLoad(unittest.TestCase):
# read the file with load and a file URL
self.assertEqual(load('file://%s' % tmp.name).read(), contents)
finally:
# remove the tempfile
if os.path.exists(tmp.name):
os.remove(tmp.name)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozfile/tests/test_move_remove.py
+++ b/testing/mozbase/mozfile/tests/test_move_remove.py
@@ -4,16 +4,18 @@ import os
import stat
import shutil
import threading
import time
import unittest
import errno
from contextlib import contextmanager
+import mozunit
+
import mozfile
import mozinfo
import stubs
def mark_readonly(path):
"""Removes all write permissions from given file/directory.
@@ -224,9 +226,9 @@ class MozFileMoveTestCase(unittest.TestC
with wait_file_opened_in_thread(file_path, 0.2):
# first move attempt should fail on windows and be retried
mozfile.move(file_path, moved_path)
self.assertFalse(os.path.exists(file_path))
self.assertTrue(os.path.isfile(moved_path))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozfile/tests/test_tempdir.py
+++ b/testing/mozbase/mozfile/tests/test_tempdir.py
@@ -7,16 +7,18 @@
"""
tests for mozfile.TemporaryDirectory
"""
from mozfile import TemporaryDirectory
import os
import unittest
+import mozunit
+
class TestTemporaryDirectory(unittest.TestCase):
def test_removed(self):
"""ensure that a TemporaryDirectory gets removed"""
path = None
with TemporaryDirectory() as tmp:
path = tmp
@@ -34,9 +36,9 @@ class TestTemporaryDirectory(unittest.Te
with TemporaryDirectory() as tmp:
path = tmp
self.assertTrue(os.path.isdir(tmp))
raise Exception("oops")
self.assertFalse(os.path.isdir(path))
self.assertFalse(os.path.exists(path))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozfile/tests/test_tempfile.py
+++ b/testing/mozbase/mozfile/tests/test_tempfile.py
@@ -7,16 +7,18 @@
"""
tests for mozfile.NamedTemporaryFile
"""
import mozfile
import os
import unittest
+import mozunit
+
class TestNamedTemporaryFile(unittest.TestCase):
"""test our fix for NamedTemporaryFile"""
def test_named_temporary_file(self):
""" Ensure the fix for re-opening a NamedTemporaryFile works
Refer to https://bugzilla.mozilla.org/show_bug.cgi?id=818777
@@ -94,9 +96,9 @@ class TestNamedTemporaryFile(unittest.Te
self.assertTrue(os.path.exists(path))
del tf
self.assertTrue(os.path.exists(path))
finally:
if path and os.path.exists(path):
os.remove(path)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozfile/tests/test_url.py
+++ b/testing/mozbase/mozfile/tests/test_url.py
@@ -2,20 +2,22 @@
"""
tests for is_url
"""
import unittest
from mozfile import is_url
+import mozunit
+
class TestIsUrl(unittest.TestCase):
"""test the is_url function"""
def test_is_url(self):
self.assertTrue(is_url('http://mozilla.org'))
self.assertFalse(is_url('/usr/bin/mozilla.org'))
self.assertTrue(is_url('file:///usr/bin/mozilla.org'))
self.assertFalse(is_url('c:\foo\bar'))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozhttpd/tests/api.py
+++ b/testing/mozbase/mozhttpd/tests/api.py
@@ -7,16 +7,18 @@
import mozfile
import mozhttpd
import urllib2
import os
import unittest
import json
import tempfile
+import mozunit
+
here = os.path.dirname(os.path.abspath(__file__))
class ApiTest(unittest.TestCase):
resource_get_called = 0
resource_post_called = 0
resource_del_called = 0
@@ -258,9 +260,9 @@ class ProxyTest(unittest.TestCase):
urllib2.urlopen(url(unproxied_host))
except urllib2.HTTPError as e:
exc = e
self.assertNotEqual(exc, None)
self.assertEqual(exc.code, 404)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozhttpd/tests/baseurl.py
+++ b/testing/mozbase/mozhttpd/tests/baseurl.py
@@ -1,19 +1,21 @@
import mozhttpd
import unittest
+import mozunit
+
class BaseUrlTest(unittest.TestCase):
def test_base_url(self):
httpd = mozhttpd.MozHttpd(port=0)
self.assertEqual(httpd.get_url(), None)
httpd.start(block=False)
self.assertEqual("http://127.0.0.1:%s/" % httpd.httpd.server_port,
httpd.get_url())
self.assertEqual("http://127.0.0.1:%s/cheezburgers.html" %
httpd.httpd.server_port,
httpd.get_url(path="/cheezburgers.html"))
httpd.stop()
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozhttpd/tests/basic.py
+++ b/testing/mozbase/mozhttpd/tests/basic.py
@@ -1,16 +1,18 @@
#!/usr/bin/env python
import mozhttpd
import mozfile
import os
import tempfile
import unittest
+import mozunit
+
class TestBasic(unittest.TestCase):
""" Test basic Mozhttpd capabilites """
def test_basic(self):
""" Test mozhttpd can serve files """
tempdir = tempfile.mkdtemp()
@@ -38,9 +40,9 @@ class TestBasic(unittest.TestCase):
for k in sizes.keys():
retrieved_content = mozfile.load(server_url + k).read()
self.assertEqual(retrieved_content, sizes[k][1])
# Cleanup tempdir and related files
mozfile.rmtree(tempdir)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozhttpd/tests/filelisting.py
+++ b/testing/mozbase/mozhttpd/tests/filelisting.py
@@ -5,16 +5,18 @@
# You can obtain one at http://mozilla.org/MPL/2.0/.
import mozhttpd
import urllib2
import os
import unittest
import re
+import mozunit
+
here = os.path.dirname(os.path.abspath(__file__))
class FileListingTest(unittest.TestCase):
def check_filelisting(self, path=''):
filelist = os.listdir(here)
@@ -35,9 +37,9 @@ class FileListingTest(unittest.TestCase)
def test_filelist(self):
self.check_filelisting()
def test_filelist_params(self):
self.check_filelisting('?foo=bar&fleem=&foo=fleem')
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozhttpd/tests/paths.py
+++ b/testing/mozbase/mozhttpd/tests/paths.py
@@ -4,16 +4,18 @@
# http://creativecommons.org/publicdomain/zero/1.0/
from mozfile import TemporaryDirectory
import mozhttpd
import os
import unittest
import urllib2
+import mozunit
+
class PathTest(unittest.TestCase):
def try_get(self, url, expected_contents):
f = urllib2.urlopen(url)
self.assertEqual(f.getcode(), 200)
self.assertEqual(f.read(), expected_contents)
@@ -69,9 +71,9 @@ class PathTest(unittest.TestCase):
with TemporaryDirectory() as d1:
httpd = mozhttpd.MozHttpd(port=0,
path_mappings={'/foo': d1})
httpd.start(block=False)
self.try_get_expect_404(httpd.get_url())
httpd.stop()
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozhttpd/tests/requestlog.py
+++ b/testing/mozbase/mozhttpd/tests/requestlog.py
@@ -2,16 +2,18 @@
# 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/.
import mozhttpd
import urllib2
import os
import unittest
+import mozunit
+
here = os.path.dirname(os.path.abspath(__file__))
class RequestLogTest(unittest.TestCase):
def check_logging(self, log_requests=False):
httpd = mozhttpd.MozHttpd(port=0, docroot=here, log_requests=log_requests)
@@ -33,9 +35,9 @@ class RequestLogTest(unittest.TestCase):
self.assertEqual(type(log_entry['time']), float)
def test_logging_disabled(self):
request_log = self.check_logging(log_requests=False)
self.assertEqual(len(request_log), 0)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozinfo/tests/test.py
+++ b/testing/mozbase/mozinfo/tests/test.py
@@ -8,16 +8,18 @@ import json
import mock
import os
import shutil
import sys
import tempfile
import unittest
import mozinfo
+import mozunit
+
class TestMozinfo(unittest.TestCase):
def setUp(self):
reload(mozinfo)
self.tempdir = os.path.abspath(tempfile.mkdtemp())
# When running from an objdir mozinfo will use a build generated json file
@@ -113,9 +115,9 @@ class TestStringVersion(unittest.TestCas
self.assertLessEqual(version, '11')
self.assertLessEqual('10.10', version)
def test_to_string(self):
self.assertEqual('10.10', str(mozinfo.StringVersion('10.10')))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozinstall/tests/test.py
+++ b/testing/mozbase/mozinstall/tests/test.py
@@ -6,16 +6,18 @@
import mozinfo
import mozinstall
import mozfile
import os
import tempfile
import unittest
+import mozunit
+
# Store file location at load time
here = os.path.dirname(os.path.abspath(__file__))
class TestMozInstall(unittest.TestCase):
@classmethod
def setUpClass(cls):
@@ -161,9 +163,9 @@ class TestMozInstall(unittest.TestCase):
self.assertFalse(os.path.exists(installdir_zip))
elif mozinfo.isMac:
installdir = mozinstall.install(self.dmg, self.tempdir)
mozinstall.uninstall(installdir)
self.assertFalse(os.path.exists(installdir))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozlog/tests/test_logger.py
+++ b/testing/mozbase/mozlog/tests/test_logger.py
@@ -4,18 +4,19 @@
import datetime
import json
import socket
import threading
import time
import unittest
+import mozunit
+
import mozfile
-
import mozlog.unstructured as mozlog
class ListHandler(mozlog.Handler):
"""Mock handler appends messages to a list for later inspection."""
def __init__(self):
mozlog.Handler.__init__(self)
@@ -227,17 +228,17 @@ class Loggable(mozlog.LoggingMixin):
class TestLoggingMixin(unittest.TestCase):
"""Tests basic use of LoggingMixin"""
def test_mixin(self):
loggable = Loggable()
self.assertTrue(not hasattr(loggable, "_logger"))
loggable.log(mozlog.INFO, "This will instantiate the logger")
self.assertTrue(hasattr(loggable, "_logger"))
- self.assertEqual(loggable._logger.name, "test_logger.Loggable")
+ self.assertEqual(loggable._logger.name, "__main__.Loggable")
self.assertRaises(ValueError, loggable.set_logger,
"not a logger")
logger = mozlog.MozLogger('test.mixin')
handler = ListHandler()
logger.addHandler(handler)
loggable.set_logger(logger)
@@ -256,9 +257,9 @@ class TestLoggingMixin(unittest.TestCase
'message for "info" method',
'message for "error" method',
'message for "log_structured" method']
actual_messages = loggable._logger.handlers[0].messages
self.assertEqual(expected_messages, actual_messages)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozlog/tests/test_structured.py
+++ b/testing/mozbase/mozlog/tests/test_structured.py
@@ -4,18 +4,19 @@ import json
import optparse
import os
import StringIO
import sys
import unittest
import signal
import xml.etree.ElementTree as ET
+import mozunit
+
import mozfile
-
from mozlog import (
commandline,
reader,
structuredlog,
stdadapter,
handlers,
formatters,
)
@@ -1090,9 +1091,9 @@ class TestReader(unittest.TestCase):
handler = ReaderTestHandler()
reader.handle_log(reader.read(f), handler)
self.assertEquals(handler.action_0_count, 1)
self.assertEquals(handler.action_1_count, 1)
if __name__ == "__main__":
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/moznetwork/tests/test.py
+++ b/testing/mozbase/moznetwork/tests/test.py
@@ -6,16 +6,18 @@ Unit-Tests for moznetwork
import os
import mock
import mozinfo
import moznetwork
import re
import subprocess
import unittest
+import mozunit
+
def verify_ip_in_list(ip):
"""
Helper Method to check if `ip` is listed in Network Adresses
returned by ipconfig/ifconfig, depending on the platform in use
:param ip: IPv4 address in the xxx.xxx.xxx.xxx format as a string
Example Usage:
@@ -77,9 +79,9 @@ class TestGetIP(unittest.TestCase):
ip = moznetwork.get_ip()
# Check the IP returned by moznetwork is in the list
self.assertTrue(verify_ip_in_list(ip))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozprocess/tests/test_mozprocess.py
+++ b/testing/mozbase/mozprocess/tests/test_mozprocess.py
@@ -2,18 +2,20 @@
# 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/.
import os
import subprocess
import sys
-import unittest
import proctest
+
+import mozunit
+
from mozprocess import processhandler
here = os.path.dirname(os.path.abspath(__file__))
def make_proclaunch(aDir):
"""
Makes the proclaunch executable.
@@ -227,9 +229,9 @@ class ProcTest(proctest.ProcTest):
p.run()
p.processOutput(timeout=5)
p.wait()
self.determine_status(p, False, ())
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozprocess/tests/test_mozprocess_kill.py
+++ b/testing/mozbase/mozprocess/tests/test_mozprocess_kill.py
@@ -1,15 +1,18 @@
#!/usr/bin/env python
import os
import time
import unittest
import proctest
import signal
+
+import mozunit
+
from mozprocess import processhandler
here = os.path.dirname(os.path.abspath(__file__))
class ProcTestKill(proctest.ProcTest):
""" Class to test various process tree killing scenatios """
@@ -83,9 +86,9 @@ class ProcTestKill(proctest.ProcTest):
p.run()
time.sleep(1)
p.kill()
self.assertEquals(p.proc.returncode, -signal.SIGKILL)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozprocess/tests/test_mozprocess_kill_broad_wait.py
+++ b/testing/mozbase/mozprocess/tests/test_mozprocess_kill_broad_wait.py
@@ -1,14 +1,16 @@
#!/usr/bin/env python
import os
import time
-import unittest
import proctest
+
+import mozunit
+
from mozprocess import processhandler
here = os.path.dirname(os.path.abspath(__file__))
class ProcTestKill(proctest.ProcTest):
""" Class to test various process tree killing scenatios """
@@ -25,9 +27,9 @@ class ProcTestKill(proctest.ProcTest):
p.run()
# Let the tree spawn a bit, before attempting to kill
time.sleep(3)
p.kill()
self.determine_status(p, expectedfail=('returncode',))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozprocess/tests/test_mozprocess_misc.py
+++ b/testing/mozbase/mozprocess/tests/test_mozprocess_misc.py
@@ -1,13 +1,15 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
-import unittest
+
+import mozunit
+
import proctest
from mozprocess import processhandler
here = os.path.dirname(os.path.abspath(__file__))
class ProcTestMisc(proctest.ProcTest):
""" Class to test misc operations """
@@ -33,9 +35,9 @@ class ProcTestMisc(proctest.ProcTest):
p = processhandler.ProcessHandler([self.python, self.proclaunch,
"process_normal_finish_python.ini"],
cwd=here, env=env)
# passes if no exceptions are raised
p.run()
p.wait()
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozprocess/tests/test_mozprocess_output.py
+++ b/testing/mozbase/mozprocess/tests/test_mozprocess_output.py
@@ -1,13 +1,15 @@
#!/usr/bin/env python
import io
import os
-import unittest
+
+import mozunit
+
import proctest
from mozprocess import processhandler
here = os.path.dirname(os.path.abspath(__file__))
class ProcTestOutput(proctest.ProcTest):
""" Class to test operations related to output handling """
@@ -49,9 +51,9 @@ class ProcTestOutput(proctest.ProcTest):
# make sure mozprocess doesn't close the stream
# since mozprocess didn't create it
self.assertFalse(buf.closed)
buf.close()
self.determine_status(p, False, ())
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozprocess/tests/test_mozprocess_params.py
+++ b/testing/mozbase/mozprocess/tests/test_mozprocess_params.py
@@ -1,15 +1,18 @@
#!/usr/bin/env python
# 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/.
import unittest
+
+import mozunit
+
from mozprocess import processhandler
class ParamTests(unittest.TestCase):
def test_process_outputline_handler(self):
"""Parameter processOutputLine is accepted with a single function"""
def output(line):
@@ -72,13 +75,10 @@ class ParamTests(unittest.TestCase):
err = None
try:
processhandler.ProcessHandler(['sleep', '1'], onFinish=[finish])
except (TypeError, AttributeError) as e:
err = e
self.assertFalse(err)
-def main():
- unittest.main()
-
if __name__ == '__main__':
- main()
+ mozunit.main()
--- a/testing/mozbase/mozprocess/tests/test_mozprocess_poll.py
+++ b/testing/mozbase/mozprocess/tests/test_mozprocess_poll.py
@@ -1,13 +1,14 @@
#!/usr/bin/env python
import os
import signal
-import unittest
+
+import mozunit
from mozprocess import processhandler
import proctest
here = os.path.dirname(os.path.abspath(__file__))
@@ -98,9 +99,9 @@ class ProcTestPoll(proctest.ProcTest):
# We killed the process, so the returncode should be < 0
self.assertEqual(returncode, -signal.SIGTERM)
self.assertEqual(returncode, p.poll())
self.determine_status(p)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozprocess/tests/test_mozprocess_wait.py
+++ b/testing/mozbase/mozprocess/tests/test_mozprocess_wait.py
@@ -1,14 +1,16 @@
#!/usr/bin/env python
import os
-import unittest
import proctest
import mozinfo
+
+import mozunit
+
from mozprocess import processhandler
here = os.path.dirname(os.path.abspath(__file__))
class ProcTestWait(proctest.ProcTest):
""" Class to test process waits and timeouts """
@@ -88,9 +90,9 @@ class ProcTestWait(proctest.ProcTest):
self.determine_status(p)
self.assertLess(returncode2, 0,
'Negative returncode expected, got "%s"' % returncode2)
self.assertEqual(returncode1, returncode2,
'Expected both returncodes of wait() to be equal')
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozprocess/tests/test_process_reader.py
+++ b/testing/mozbase/mozprocess/tests/test_process_reader.py
@@ -1,11 +1,14 @@
import unittest
import subprocess
import sys
+
+import mozunit
+
from mozprocess.processhandler import ProcessReader, StoreOutput
def run_python(str_code, stdout=subprocess.PIPE, stderr=subprocess.PIPE):
cmd = [sys.executable, '-c', str_code]
return subprocess.Popen(cmd, stdout=stdout, stderr=stderr)
@@ -92,10 +95,11 @@ class TestProcessReader(unittest.TestCas
proc = run_python('import sys; sys.stderr.write("hello world\\n"); print 1; print 2',
stderr=subprocess.STDOUT)
self.reader.start(proc)
self.reader.thread.join()
self.assertEqual(sorted(self.out.output), sorted(['1', '2', 'hello world']))
self.assertEqual(self.err.output, [])
+
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozprofile/tests/addonid.py
+++ b/testing/mozbase/mozprofile/tests/addonid.py
@@ -1,14 +1,17 @@
#!/usr/bin/env python
import os
import tempfile
import unittest
import shutil
+
+import mozunit
+
from mozprofile import addons
here = os.path.dirname(os.path.abspath(__file__))
class AddonIDTest(unittest.TestCase):
""" Test finding the addon id in a variety of install.rdf styles """
@@ -176,9 +179,9 @@ class AddonIDTest(unittest.TestCase):
</Description>
</em:targetApplication>
</Description>
</RDF>
"""]
return tests
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozprofile/tests/bug758250.py
+++ b/testing/mozbase/mozprofile/tests/bug758250.py
@@ -1,16 +1,18 @@
#!/usr/bin/env python
import mozprofile
import os
import shutil
import tempfile
import unittest
+import mozunit
+
here = os.path.dirname(os.path.abspath(__file__))
class Bug758250(unittest.TestCase):
"""
use of --profile in mozrunner just blows away addon sources:
https://bugzilla.mozilla.org/show_bug.cgi?id=758250
@@ -45,9 +47,9 @@ class Bug758250(unittest.TestCase):
newprofile.cleanup()
# the source addon *should* still exist
self.assertTrue(os.path.exists(self.tmpdir))
self.assertTrue(os.path.exists(os.path.join(self.tmpdir, 'install.rdf')))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozprofile/tests/bug785146.py
+++ b/testing/mozbase/mozprofile/tests/bug785146.py
@@ -5,16 +5,19 @@
# You can obtain one at http://mozilla.org/MPL/2.0/.
import mozfile
import os
import shutil
import sqlite3
import tempfile
import unittest
+
+import mozunit
+
from mozprofile.permissions import Permissions
class PermissionsTest(unittest.TestCase):
locations = """http://mochi.test:8888 primary,privileged
http://127.0.0.1:80 noxul
http://127.0.0.1:8888 privileged
@@ -43,9 +46,9 @@ http://127.0.0.1:8888 privileg
cur = con.cursor()
cur.execute(stmt)
entries = cur.fetchall()
schema_version = entries[0][0]
self.assertEqual(schema_version, 5)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozprofile/tests/permissions.py
+++ b/testing/mozbase/mozprofile/tests/permissions.py
@@ -5,16 +5,19 @@
# You can obtain one at http://mozilla.org/MPL/2.0/.
import mozfile
import os
import shutil
import sqlite3
import tempfile
import unittest
+
+import mozunit
+
from mozprofile.permissions import Permissions
class PermissionsTest(unittest.TestCase):
locations = """http://mochi.test:8888 primary,privileged
http://127.0.0.1:80 noxul
http://127.0.0.1:8888 privileged
@@ -191,9 +194,9 @@ http://127.0.0.1:8888 privileg
def test_existing_permissions_db_v4(self):
self.verify_user_version(4)
def test_existing_permissions_db_v5(self):
self.verify_user_version(5)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozprofile/tests/server_locations.py
+++ b/testing/mozbase/mozprofile/tests/server_locations.py
@@ -1,16 +1,19 @@
#!/usr/bin/env python
# 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/.
import mozfile
import unittest
+
+import mozunit
+
from mozprofile.permissions import ServerLocations, \
MissingPrimaryLocationError, MultiplePrimaryLocationsError, \
DuplicateLocationError, BadPortLocationError, LocationsSyntaxError
class ServerLocationsTest(unittest.TestCase):
"""test server locations"""
@@ -143,9 +146,9 @@ http://example.org:80 privileg
# read a second file, which should generate a callback with both
# locations.
f = self.create_temp_file(self.locations_no_primary)
locations.read(f.name)
self.assertEqual(len(c.last_locations), 2)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozprofile/tests/test_addons.py
+++ b/testing/mozbase/mozprofile/tests/test_addons.py
@@ -5,16 +5,18 @@
# You can obtain one at http://mozilla.org/MPL/2.0/.
import os
import shutil
import tempfile
import unittest
import urllib2
+import mozunit
+
from manifestparser import ManifestParser
import mozfile
import mozhttpd
import mozlog.unstructured as mozlog
import mozprofile
from addon_stubs import generate_addon, generate_manifest
@@ -407,9 +409,9 @@ class TestAddonsManager(unittest.TestCas
for addon in self.am._addons:
self.am.remove_addon(addon)
self.assertEqual(os.listdir(staging_path), [])
self.assertEqual(os.listdir(extensions_path), ['staged'])
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozprofile/tests/test_clone_cleanup.py
+++ b/testing/mozbase/mozprofile/tests/test_clone_cleanup.py
@@ -5,16 +5,18 @@
# You can obtain one at http://mozilla.org/MPL/2.0/.
import os
import tempfile
import unittest
import mozfile
+import mozunit
+
from mozprofile.profile import Profile
class CloneCleanupTest(unittest.TestCase):
"""
test cleanup logic for the clone functionality
see https://bugzilla.mozilla.org/show_bug.cgi?id=642843
"""
@@ -55,9 +57,9 @@ class CloneCleanupTest(unittest.TestCase
profile_dir = clone.profile
self.assertTrue(os.path.exists(profile_dir))
del clone
# clone should be deleted
self.assertFalse(os.path.exists(profile_dir))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozprofile/tests/test_nonce.py
+++ b/testing/mozbase/mozprofile/tests/test_nonce.py
@@ -4,16 +4,19 @@
test nonce in prefs delimeters
see https://bugzilla.mozilla.org/show_bug.cgi?id=722804
"""
import os
import tempfile
import unittest
import mozfile
+
+import mozunit
+
from mozprofile.prefs import Preferences
from mozprofile.profile import Profile
class PreferencesNonceTest(unittest.TestCase):
def test_nonce(self):
@@ -41,9 +44,9 @@ class PreferencesNonceTest(unittest.Test
# cleanup the profile;
# this should remove the new preferences but not the old
profile.cleanup()
prefs = Preferences.read_prefs(user_js)
self.assertEqual(dict(prefs), {'foo': 'bar'})
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozprofile/tests/test_preferences.py
+++ b/testing/mozbase/mozprofile/tests/test_preferences.py
@@ -5,16 +5,19 @@
# You can obtain one at http://mozilla.org/MPL/2.0/.
import mozfile
import mozhttpd
import os
import shutil
import tempfile
import unittest
+
+import mozunit
+
from mozprofile.cli import MozProfileCLI
from mozprofile.prefs import Preferences
from mozprofile.profile import Profile
here = os.path.dirname(os.path.abspath(__file__))
class PreferencesTest(unittest.TestCase):
@@ -370,9 +373,9 @@ user_pref("webgl.force-enabled", true);
# read preferences through the web
read = prefs.read_prefs('http://%s:%d/prefs_with_comments.js' % (host, port))
self.assertEqual(dict(read), self._prefs_with_comments)
finally:
httpd.stop()
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozprofile/tests/test_profile.py
+++ b/testing/mozbase/mozprofile/tests/test_profile.py
@@ -1,16 +1,19 @@
#!/usr/bin/env python
# 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/.
import unittest
import os
+
+import mozunit
+
from mozprofile import Profile
class TestProfile(unittest.TestCase):
def test_with_profile_should_cleanup(self):
with Profile() as profile:
self.assertTrue(os.path.exists(profile.profile))
@@ -22,9 +25,9 @@ class TestProfile(unittest.TestCase):
with Profile() as profile:
self.assertTrue(os.path.exists(profile.profile))
1 / 0 # will raise ZeroDivisionError
# profile is cleaned
self.assertFalse(os.path.exists(profile.profile))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozprofile/tests/test_profile_view.py
+++ b/testing/mozbase/mozprofile/tests/test_profile_view.py
@@ -5,16 +5,18 @@
# You can obtain one at http://mozilla.org/MPL/2.0/.
import mozfile
import mozprofile
import os
import tempfile
import unittest
+import mozunit
+
here = os.path.dirname(os.path.abspath(__file__))
class TestProfilePrint(unittest.TestCase):
def test_profileprint(self):
"""
test the summary function
@@ -67,9 +69,9 @@ class TestProfilePrint(unittest.TestCase
self.assertEqual(diff.keys(), ['user.js'])
lines = [line.strip() for line in diff['user.js'].splitlines()]
self.assertTrue('-foo: bar' in lines)
ff_pref_lines = ['+%s: %s' % (key, value)
for key, value in mozprofile.FirefoxProfile.preferences.items()]
self.assertTrue(set(ff_pref_lines).issubset(lines))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozprofile/tests/test_webapps.py
+++ b/testing/mozbase/mozprofile/tests/test_webapps.py
@@ -4,16 +4,18 @@
test installing and managing webapps in a profile
"""
import os
import shutil
import unittest
from tempfile import mkdtemp
+import mozunit
+
from mozprofile.webapps import WebappCollection, Webapp, WebappFormatException
here = os.path.dirname(os.path.abspath(__file__))
class WebappTest(unittest.TestCase):
"""Tests reading, installing and cleaning webapps
from a profile.
@@ -194,9 +196,9 @@ class WebappTest(unittest.TestCase):
webapps_json = webapps.read_json(self.webapps_json_path)
for app in webapps_json:
self.assertIsInstance(app, Webapp)
self.assertTrue(os.path.isfile(os.path.join(self.webapps_dir, app['name'],
'manifest.webapp')))
self.assertEqual(webapps_json, manifest_json_2)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozrunner/tests/test_crash.py
+++ b/testing/mozbase/mozrunner/tests/test_crash.py
@@ -1,14 +1,15 @@
#!/usr/bin/env python
# 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/.
import mock
+import mozunit
import mozrunnertest
class MozrunnerCrashTestCase(mozrunnertest.MozrunnerTestCase):
@mock.patch('mozcrash.log_crashes', return_value=2)
def test_crash_count_with_logger(self, log_crashes):
@@ -30,8 +31,12 @@ class MozrunnerCrashTestCase(mozrunnerte
self.assertEqual(self.runner.check_for_crashes(), 2)
self.assertEqual(self.runner.crashed, 2)
self.assertEqual(self.runner.check_for_crashes(), 2)
self.assertEqual(self.runner.crashed, 4)
check_for_crashes.return_value = 0
self.assertEqual(self.runner.check_for_crashes(), 0)
self.assertEqual(self.runner.crashed, 4)
+
+
+if __name__ == '__main__':
+ mozunit.main()
--- a/testing/mozbase/mozrunner/tests/test_interactive.py
+++ b/testing/mozbase/mozrunner/tests/test_interactive.py
@@ -1,13 +1,15 @@
#!/usr/bin/env python
import threading
from time import sleep
+import mozunit
+
import mozrunnertest
class RunnerThread(threading.Thread):
def __init__(self, runner, timeout=10):
threading.Thread.__init__(self)
self.runner = runner
@@ -46,8 +48,12 @@ class MozrunnerInteractiveTestCase(mozru
self.runner.start(interactive=True)
sleep(5)
self.runner.process_handler.kill()
returncode = self.runner.wait(1)
self.assertNotIn(returncode, [None, 0])
self.assertIsNotNone(self.runner.process_handler)
+
+
+if __name__ == '__main__':
+ mozunit.main()
--- a/testing/mozbase/mozrunner/tests/test_start.py
+++ b/testing/mozbase/mozrunner/tests/test_start.py
@@ -1,12 +1,14 @@
#!/usr/bin/env python
from time import sleep
+import mozunit
+
import mozrunnertest
class MozrunnerStartTestCase(mozrunnertest.MozrunnerTestCase):
def test_start_process(self):
"""Start the process and test properties"""
self.assertIsNone(self.runner.process_handler)
@@ -38,8 +40,12 @@ class MozrunnerStartTestCase(mozrunnerte
self.assertFalse(self.runner.is_running())
def test_start_with_outputTimeout(self):
"""Start the process and set a timeout"""
self.runner.start(outputTimeout=2)
sleep(15)
self.assertFalse(self.runner.is_running())
+
+
+if __name__ == '__main__':
+ mozunit.main()
--- a/testing/mozbase/mozrunner/tests/test_states.py
+++ b/testing/mozbase/mozrunner/tests/test_states.py
@@ -1,18 +1,24 @@
#!/usr/bin/env python
import mozrunner
+import mozunit
+
import mozrunnertest
class MozrunnerStatesTestCase(mozrunnertest.MozrunnerTestCase):
def test_errors_before_start(self):
"""Bug 965714: Not started errors before start() is called"""
def test_returncode():
return self.runner.returncode
self.assertRaises(mozrunner.RunnerNotStartedError, self.runner.is_running)
self.assertRaises(mozrunner.RunnerNotStartedError, test_returncode)
self.assertRaises(mozrunner.RunnerNotStartedError, self.runner.wait)
+
+
+if __name__ == '__main__':
+ mozunit.main()
--- a/testing/mozbase/mozrunner/tests/test_stop.py
+++ b/testing/mozbase/mozrunner/tests/test_stop.py
@@ -1,15 +1,17 @@
#!/usr/bin/env python
# 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/.
import signal
+import mozunit
+
import mozrunnertest
class MozrunnerStopTestCase(mozrunnertest.MozrunnerTestCase):
def test_stop_process(self):
"""Stop the process and test properties"""
self.runner.start()
@@ -32,8 +34,12 @@ class MozrunnerStopTestCase(mozrunnertes
returncode = self.runner.stop(signal.SIGTERM)
self.assertFalse(self.runner.is_running())
self.assertNotIn(returncode, [None, 0])
self.assertEqual(self.runner.returncode, returncode)
self.assertIsNotNone(self.runner.process_handler)
self.assertEqual(self.runner.wait(1), returncode)
+
+
+if __name__ == '__main__':
+ mozunit.main()
--- a/testing/mozbase/mozrunner/tests/test_threads.py
+++ b/testing/mozbase/mozrunner/tests/test_threads.py
@@ -1,16 +1,18 @@
#!/usr/bin/env python
# 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/.
import threading
from time import sleep
+import mozunit
+
import mozrunnertest
class RunnerThread(threading.Thread):
def __init__(self, runner, do_start, timeout=10):
threading.Thread.__init__(self)
self.runner = runner
@@ -66,8 +68,12 @@ class MozrunnerThreadsTestCase(mozrunner
self.runner.wait(2)
returncode = self.runner.stop()
thread.join()
self.assertNotIn(returncode, [None, 0])
self.assertEqual(self.runner.returncode, returncode)
self.assertIsNotNone(self.runner.process_handler)
self.assertEqual(self.runner.wait(10), returncode)
+
+
+if __name__ == '__main__':
+ mozunit.main()
--- a/testing/mozbase/mozrunner/tests/test_wait.py
+++ b/testing/mozbase/mozrunner/tests/test_wait.py
@@ -1,13 +1,14 @@
#!/usr/bin/env python
# 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/.
+import mozunit
import mozrunnertest
class MozrunnerWaitTestCase(mozrunnertest.MozrunnerTestCase):
def test_wait_while_running(self):
"""Wait for the process while it is running"""
self.runner.start()
@@ -22,8 +23,12 @@ class MozrunnerWaitTestCase(mozrunnertes
"""Bug 965714: wait() after stop should not raise an error"""
self.runner.start()
self.runner.process_handler.kill()
returncode = self.runner.wait(1)
self.assertNotIn(returncode, [None, 0])
self.assertIsNotNone(self.runner.process_handler)
+
+
+if __name__ == '__main__':
+ mozunit.main()
--- a/testing/mozbase/mozsystemmonitor/tests/test_resource_monitor.py
+++ b/testing/mozbase/mozsystemmonitor/tests/test_resource_monitor.py
@@ -1,16 +1,18 @@
# 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/.
import multiprocessing
import time
import unittest
+import mozunit
+
try:
import psutil
except ImportError:
psutil = None
from mozsystemmonitor.resourcemonitor import (
SystemResourceMonitor,
SystemResourceUsage,
@@ -176,9 +178,9 @@ class TestResourceMonitor(unittest.TestC
self.assertIn('system', d)
self.assertIsInstance(d['system'], dict)
self.assertIsInstance(d['overall'], dict)
self.assertIn('duration', d['overall'])
self.assertIn('cpu_times', d['overall'])
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/moztest/tests/test.py
+++ b/testing/mozbase/moztest/tests/test.py
@@ -1,16 +1,18 @@
# 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/.
import math
import time
import unittest
+import mozunit
+
from moztest.results import TestContext, TestResult, TestResultCollection
class Result(unittest.TestCase):
def test_results(self):
self.assertRaises(AssertionError,
lambda: TestResult('test', result_expected='hello'))
@@ -47,9 +49,9 @@ class Collection(unittest.TestCase):
self.collection = TestResultCollection('tests')
self.collection.extend([t1, t2, t3, t4])
def test_unique_contexts(self):
self.assertEqual(len(self.collection.contexts), 3)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozversion/tests/test_apk.py
+++ b/testing/mozbase/mozversion/tests/test_apk.py
@@ -2,16 +2,19 @@
# 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/.
import mozfile
import unittest
import zipfile
+
+import mozunit
+
from mozversion import get_version
class ApkTest(unittest.TestCase):
"""test getting version information from an android .apk"""
application_changeset = 'a' * 40
platform_changeset = 'b' * 40
@@ -35,9 +38,9 @@ class ApkTest(unittest.TestCase):
with mozfile.NamedTemporaryFile() as f:
with zipfile.ZipFile(f.name, 'w') as z:
self.create_apk_zipfiles(z)
z.writestr('package-name.txt', "org.mozilla.fennec")
v = get_version(f.name)
self.assertEqual(v.get('package_name'), "org.mozilla.fennec")
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozversion/tests/test_b2g.py
+++ b/testing/mozbase/mozversion/tests/test_b2g.py
@@ -4,16 +4,18 @@
# 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/.
import os
import tempfile
import unittest
import zipfile
+import mozunit
+
import mozfile
from mozversion import get_version, errors
class SourcesTest(unittest.TestCase):
"""test getting version information from a sources xml"""
def setUp(self):
@@ -67,9 +69,9 @@ class SourcesTest(unittest.TestCase):
v = get_version(self.binary)
self.assertIsNone(v.get('gaia_changeset'))
self.assertIsNone(v.get('gaia_date'))
def test_b2g_fallback_when_no_binary(self):
self.assertRaises(errors.RemoteAppNotFoundError, get_version)
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozversion/tests/test_binary.py
+++ b/testing/mozbase/mozversion/tests/test_binary.py
@@ -5,18 +5,19 @@
# You can obtain one at http://mozilla.org/MPL/2.0/.
import os
import sys
import tempfile
import shutil
import unittest
+import mozunit
+
import mozfile
-
from mozversion import errors, get_version
class BinaryTest(unittest.TestCase):
"""test getting application version information from a binary path"""
application_ini = """[App]
ID = AppID
@@ -169,9 +170,9 @@ SourceRepository = PlatformSourceRepo
self.assertEqual(
version.get('platform_changeset'), 'PlatformSourceStamp')
self.assertIsNone(version.get('invalid_key'))
self.assertEqual(
version.get('platform_version'), 'PlatformMilestone')
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()
--- a/testing/mozbase/mozversion/tests/test_sources.py
+++ b/testing/mozbase/mozversion/tests/test_sources.py
@@ -3,18 +3,19 @@
# 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/.
import os
import tempfile
import unittest
+import mozunit
+
import mozfile
-
from mozversion import errors, get_version
class SourcesTest(unittest.TestCase):
"""test getting version information from a sources xml"""
application_ini = """[App]\nName = B2G\n"""
platform_ini = """[Build]
@@ -77,9 +78,9 @@ SourceRepository = PlatformSourceRepo
def _check_version(self, version):
self.assertEqual(version.get('build_changeset'), 'build_revision')
self.assertEqual(version.get('gaia_changeset'), 'gaia_revision')
self.assertEqual(version.get('gecko_changeset'), 'gecko_revision')
self.assertIsNone(version.get('invalid_key'))
if __name__ == '__main__':
- unittest.main()
+ mozunit.main()