tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_testmanifest.py (4657B)


      1 #!/usr/bin/env python
      2 
      3 import os
      4 import shutil
      5 import tempfile
      6 import unittest
      7 
      8 import mozunit
      9 from manifestparser import ParseError, TestManifest
     10 from manifestparser.filters import subsuite
     11 
     12 here = os.path.dirname(os.path.abspath(__file__))
     13 
     14 
     15 class TestTestManifest(unittest.TestCase):
     16    """Test the Test Manifest"""
     17 
     18    def test_testmanifest_toml(self):
     19        # Test filtering based on platform:
     20        filter_example = os.path.join(here, "filter-example.toml")
     21        manifest = TestManifest(
     22            manifests=(filter_example,), strict=False, use_toml=True
     23        )
     24        self.assertEqual(
     25            [
     26                i["name"]
     27                for i in manifest.active_tests(os="win", disabled=False, exists=False)
     28            ],
     29            ["windowstest", "fleem"],
     30        )
     31        self.assertEqual(
     32            [
     33                i["name"]
     34                for i in manifest.active_tests(os="linux", disabled=False, exists=False)
     35            ],
     36            ["fleem", "linuxtest"],
     37        )
     38 
     39        # Look for existing tests.  There is only one:
     40        self.assertEqual([i["name"] for i in manifest.active_tests()], ["fleem"])
     41 
     42        # You should be able to expect failures:
     43        last = manifest.active_tests(exists=False, os="linux")[-1]
     44        self.assertEqual(last["name"], "linuxtest")
     45        self.assertEqual(last["expected"], "pass")
     46        last = manifest.active_tests(exists=False, os="mac")[-1]
     47        self.assertEqual(last["expected"], "fail")
     48 
     49    def test_missing_paths_toml(self):
     50        """
     51        Test paths that don't exist raise an exception in strict mode. (TOML)
     52        """
     53        tempdir = tempfile.mkdtemp()
     54 
     55        missing_path = os.path.join(here, "missing-path.toml")
     56        manifest = TestManifest(manifests=(missing_path,), strict=True, use_toml=True)
     57        self.assertRaises(IOError, manifest.active_tests)
     58        self.assertRaises(IOError, manifest.copy, tempdir)
     59        self.assertRaises(IOError, manifest.update, tempdir)
     60 
     61        shutil.rmtree(tempdir)
     62 
     63    def test_comments_toml(self):
     64        """
     65        ensure comments work, see
     66        https://bugzilla.mozilla.org/show_bug.cgi?id=813674
     67        (TOML)
     68        """
     69        comment_example = os.path.join(here, "comment-example.toml")
     70        manifest = TestManifest(manifests=(comment_example,), use_toml=True)
     71        self.assertEqual(len(manifest.tests), 8)
     72        names = [i["name"] for i in manifest.tests]
     73        self.assertFalse("test_0202_app_launch_apply_update_dirlocked.js" in names)
     74 
     75    def test_manifest_subsuites_toml(self):
     76        """
     77        test subsuites and conditional subsuites (TOML)
     78        """
     79        relative_path = os.path.join(here, "subsuite.toml")
     80        manifest = TestManifest(manifests=(relative_path,), use_toml=True)
     81        info = {"foo": "bar"}
     82 
     83        # 6 tests total
     84        tests = manifest.active_tests(exists=False, **info)
     85        self.assertEqual(len(tests), 6)
     86 
     87        # only 3 tests for subsuite bar when foo==bar
     88        tests = manifest.active_tests(exists=False, filters=[subsuite("bar")], **info)
     89        self.assertEqual(len(tests), 3)
     90 
     91        # only 1 test for subsuite baz, regardless of conditions
     92        other = {"something": "else"}
     93        tests = manifest.active_tests(exists=False, filters=[subsuite("baz")], **info)
     94        self.assertEqual(len(tests), 1)
     95        tests = manifest.active_tests(exists=False, filters=[subsuite("baz")], **other)
     96        self.assertEqual(len(tests), 1)
     97 
     98        # 4 tests match when the condition doesn't match (all tests except
     99        # the unconditional subsuite)
    100        info = {"foo": "blah"}
    101        tests = manifest.active_tests(exists=False, filters=[subsuite()], **info)
    102        self.assertEqual(len(tests), 5)
    103 
    104        # test for illegal subsuite value
    105        manifest.tests[0]["subsuite"] = 'subsuite=bar,foo=="bar",type="nothing"'
    106        with self.assertRaises(ParseError):
    107            manifest.active_tests(exists=False, filters=[subsuite("foo")], **info)
    108 
    109    def test_none_and_empty_manifest_toml(self):
    110        """
    111        Test TestManifest for None and empty manifest, see
    112        https://bugzilla.mozilla.org/show_bug.cgi?id=1087682
    113        (TOML)
    114        """
    115        none_manifest = TestManifest(manifests=None, strict=False, use_toml=True)
    116        self.assertEqual(len(none_manifest.test_paths()), 0)
    117        self.assertEqual(len(none_manifest.active_tests()), 0)
    118 
    119        empty_manifest = TestManifest(manifests=[], strict=False)
    120        self.assertEqual(len(empty_manifest.test_paths()), 0)
    121        self.assertEqual(len(empty_manifest.active_tests()), 0)
    122 
    123 
    124 if __name__ == "__main__":
    125    mozunit.main()