Пример #1
0
    def install_from_manifest(self, filepath):
        """
        Installs addons from a manifest
        :param filepath: path to the manifest of addons to install
        """
        manifest = ManifestParser()
        manifest.read(filepath)
        addons = manifest.get()

        for addon in addons:
            if '://' in addon['path'] or os.path.exists(addon['path']):
                self.install_from_path(addon['path'])
                continue

            # No path specified, try to grab it off AMO
            locale = addon.get('amo_locale', 'en_US')
            query = 'https://services.addons.mozilla.org/' + locale + '/firefox/api/' + AMO_API_VERSION + '/'
            if 'amo_id' in addon:
                query += 'addon/' + addon['amo_id']                 # this query grabs information on the addon base on its id
            else:
                query += 'search/' + addon['name'] + '/default/1'   # this query grabs information on the first addon returned from a search
            install_path = AddonManager.get_amo_install_path(query)
            self.install_from_path(install_path)

        self.installed_manifests.append(filepath)
Пример #2
0
    def test_convert_directory_manifests_in_place(self):
        """
        keep the manifests in place
        """

        stub = self.create_stub()
        try:
            ManifestParser.populate_directory_manifests([stub], filename="manifest.ini")
            self.assertEqual(
                sorted(os.listdir(stub)),
                ["bar", "fleem", "foo", "manifest.ini", "subdir"],
            )
            parser = ManifestParser()
            parser.read(os.path.join(stub, "manifest.ini"))
            self.assertEqual(
                [i["name"] for i in parser.tests], ["subfile", "bar", "fleem", "foo"]
            )
            parser = ManifestParser()
            parser.read(os.path.join(stub, "subdir", "manifest.ini"))
            self.assertEqual(len(parser.tests), 1)
            self.assertEqual(parser.tests[0]["name"], "subfile")
        except BaseException:
            raise
        finally:
            shutil.rmtree(stub)
Пример #3
0
    def test_include_manifest_defaults(self):
        """
        Test that manifest_defaults and manifests() are correctly populated
        when includes are used.
        """

        include_example = os.path.join(here, 'include-example.ini')
        noinclude_example = os.path.join(here, 'just-defaults.ini')
        bar_path = os.path.join(here, 'include', 'bar.ini')
        foo_path = os.path.join(here, 'include', 'foo.ini')

        parser = ManifestParser(manifests=(include_example, noinclude_example))

        # Standalone manifests must be appear as-is.
        self.assertTrue(include_example in parser.manifest_defaults)
        self.assertTrue(noinclude_example in parser.manifest_defaults)

        # Included manifests must only appear together with the parent manifest
        # that included the manifest.
        self.assertFalse(bar_path in parser.manifest_defaults)
        self.assertFalse(foo_path in parser.manifest_defaults)
        self.assertTrue((include_example,
                         bar_path) in parser.manifest_defaults)
        self.assertTrue((include_example,
                         foo_path) in parser.manifest_defaults)

        # manifests() must only return file paths (strings).
        manifests = parser.manifests()
        self.assertEqual(len(manifests), 4)
        self.assertIn(foo_path, manifests)
        self.assertIn(bar_path, manifests)
        self.assertIn(include_example, manifests)
        self.assertIn(noinclude_example, manifests)
Пример #4
0
    def install_from_manifest(self, filepath):
        """
        Installs addons from a manifest
        :param filepath: path to the manifest of addons to install
        """
        try:
            from manifestparser import ManifestParser
        except ImportError:
            module_logger.critical(
                "Installing addons from manifest requires the"
                " manifestparser package to be installed.")
            raise

        manifest = ManifestParser()
        manifest.read(filepath)
        addons = manifest.get()

        for addon in addons:
            if '://' in addon['path'] or os.path.exists(addon['path']):
                self.install_from_path(addon['path'])
                continue

            # No path specified, try to grab it off AMO
            locale = addon.get('amo_locale', 'en_US')
            query = 'https://services.addons.mozilla.org/' + locale + '/firefox/api/' + AMO_API_VERSION + '/'
            if 'amo_id' in addon:
                query += 'addon/' + addon[
                    'amo_id']  # this query grabs information on the addon base on its id
            else:
                query += 'search/' + addon[
                    'name'] + '/default/1'  # this query grabs information on the first addon returned from a search
            install_path = AddonManager.get_amo_install_path(query)
            self.install_from_path(install_path)

        self.installed_manifests.append(filepath)
    def test_parent_inheritance(self):
        """
        Test parent manifest variable inheritance
        Specifically tests that inherited variables from parent includes
        properly propagate downstream
        """
        parent_example = os.path.join(here, 'parent', 'level_1', 'level_2',
                                      'level_3', 'level_3.ini')
        parser = ManifestParser(manifests=(parent_example,))

        # Parent manifest test should not be included
        self.assertEqual(parser.get('name'),
                         ['test_3'])
        self.assertEqual([(test['name'], os.path.basename(test['manifest']))
                          for test in parser.tests],
                         [('test_3', 'level_3.ini')])

        # DEFAULT values should be the ones from level 1
        self.assertEqual(parser.get('name', x='level_1'),
                         ['test_3'])

        # Write the output to a manifest:
        buffer = StringIO()
        parser.write(fp=buffer, global_kwargs={'x': 'level_1'})
        self.assertEqual(buffer.getvalue().strip(),
                         '[DEFAULT]\nx = level_1\n\n[test_3]\nsubsuite =')
Пример #6
0
    def install_from_manifest(self, filepath):
        """
        Installs addons from a manifest
        :param filepath: path to the manifest of addons to install
        """
        manifest = ManifestParser()
        manifest.read(filepath)
        addons = manifest.get()

        for addon in addons:
            if "://" in addon["path"] or os.path.exists(addon["path"]):
                self.install_from_path(addon["path"])
                continue

            # No path specified, try to grab it off AMO
            locale = addon.get("amo_locale", "en_US")
            query = "https://services.addons.mozilla.org/" + locale + "/firefox/api/" + AMO_API_VERSION + "/"
            if "amo_id" in addon:
                query += "addon/" + addon["amo_id"]  # this query grabs information on the addon base on its id
            else:
                query += (
                    "search/" + addon["name"] + "/default/1"
                )  # this query grabs information on the first addon returned from a search
            install_path = AddonManager.get_amo_install_path(query)
            self.install_from_path(install_path)

        self.installed_manifests.append(filepath)
Пример #7
0
    def test_recursion_symlinks(self):
        workspace = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, workspace)

        # create two dirs
        os.makedirs(os.path.join(workspace, 'dir1'))
        os.makedirs(os.path.join(workspace, 'dir2'))

        # create cyclical symlinks
        os.symlink(os.path.join('..', 'dir1'),
                   os.path.join(workspace, 'dir2', 'ldir1'))
        os.symlink(os.path.join('..', 'dir2'),
                   os.path.join(workspace, 'dir1', 'ldir2'))

        # create one file in each dir
        open(os.path.join(workspace, 'dir1', 'f1.txt'), 'a').close()
        open(os.path.join(workspace, 'dir1', 'ldir2', 'f2.txt'), 'a').close()

        data = []

        def callback(rootdirectory, directory, subdirs, files):
            for f in files:
                data.append(f)

        ManifestParser._walk_directories([workspace], callback)
        self.assertEqual(sorted(data), ['f1.txt', 'f2.txt'])
Пример #8
0
def create_gallery_generator(command_line_arguments, css_directory):
  """
  Given command line arguments, wire up the application and return
  it to the main function. This requires creating most of the objects
  described in the other files from this directory.

  Args:
    command_line_arguments the command line arguments with the program
                           name removed.
    css_directory the directory containing the CSS files.
  """
  input_data = parse_command_line_arguments(command_line_arguments)
  # First parse the manifest file
  with open(input_data['manifest_file'], 'r') as manifest_file:
    parser = ManifestParser(manifest_file)
    lookup_table = parser.get_json_data()
  factory = GalleryItemFactory(lookup_table, input_data['should_prompt'])
  template_exporter = exporter.create_photo_directory_exporter()
  template_writer = \
      templatewriter.create_template_writer(input_data['output_directory'])
  return GalleryGenerator(gallery_item_factory=factory,
      input_directory=input_data['input_directory'],
      output_directory=input_data['output_directory'],
      static_files_directory=css_directory,
      exporter=template_exporter,
      template_writer=template_writer)
Пример #9
0
    def install_from_manifest(self, filepath):
        """
        Installs addons from a manifest
        filepath - path to the manifest of addons to install
        """
        manifest = ManifestParser()
        manifest.read(filepath)
        addons = manifest.get()

        for addon in addons:
            if '://' in addon['path'] or os.path.exists(addon['path']):
                self.install_from_path(addon['path'])
                continue

            # No path specified, try to grab it off AMO
            locale = addon.get('amo_locale', 'en_US')

            query = 'https://services.addons.mozilla.org/' + locale + '/firefox/api/' + AMO_API_VERSION + '/'
            if 'amo_id' in addon:
                query += 'addon/' + addon[
                    'amo_id']  # this query grabs information on the addon base on its id
            else:
                query += 'search/' + addon[
                    'name'] + '/default/1'  # this query grabs information on the first addon returned from a search
            install_path = AddonManager.get_amo_install_path(query)
            self.install_from_path(install_path)
Пример #10
0
    def test_sanity(self):
        """Ensure basic parser is sane"""

        parser = ManifestParser()
        mozmill_example = os.path.join(here, 'mozmill-example.ini')
        parser.read(mozmill_example)
        tests = parser.tests
        self.assertEqual(
            len(tests), len(file(mozmill_example).read().strip().splitlines()))

        # Ensure that capitalization and order aren't an issue:
        lines = ['[%s]' % test['name'] for test in tests]
        self.assertEqual(lines,
                         file(mozmill_example).read().strip().splitlines())

        # Show how you select subsets of tests:
        mozmill_restart_example = os.path.join(here,
                                               'mozmill-restart-example.ini')
        parser.read(mozmill_restart_example)
        restart_tests = parser.get(type='restart')
        self.assertTrue(len(restart_tests) < len(parser.tests))
        self.assertEqual(len(restart_tests),
                         len(parser.get(manifest=mozmill_restart_example)))
        self.assertFalse([
            test for test in restart_tests if test['manifest'] != os.path.join(
                here, 'mozmill-restart-example.ini')
        ])
        self.assertEqual(parser.get('name', tags=['foo']), [
            'restartTests/testExtensionInstallUninstall/test2.js',
            'restartTests/testExtensionInstallUninstall/test1.js'
        ])
        self.assertEqual(
            parser.get('name', foo='bar'),
            ['restartTests/testExtensionInstallUninstall/test2.js'])
Пример #11
0
    def test_recursion_symlinks(self):
        workspace = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, workspace)

        # create two dirs
        os.makedirs(os.path.join(workspace, 'dir1'))
        os.makedirs(os.path.join(workspace, 'dir2'))

        # create cyclical symlinks
        os.symlink(os.path.join('..', 'dir1'),
                   os.path.join(workspace, 'dir2', 'ldir1'))
        os.symlink(os.path.join('..', 'dir2'),
                   os.path.join(workspace, 'dir1', 'ldir2'))

        # create one file in each dir
        open(os.path.join(workspace, 'dir1', 'f1.txt'), 'a').close()
        open(os.path.join(workspace, 'dir1', 'ldir2', 'f2.txt'), 'a').close()

        data = []

        def callback(rootdirectory, directory, subdirs, files):
            for f in files:
                data.append(f)

        ManifestParser._walk_directories([workspace], callback)
        self.assertEqual(sorted(data), ['f1.txt', 'f2.txt'])
Пример #12
0
    def test_just_defaults(self):
        """Ensure a manifest with just a DEFAULT section exposes that data."""

        parser = ManifestParser()
        manifest = os.path.join(here, 'just-defaults.ini')
        parser.read(manifest)
        self.assertEqual(len(parser.tests), 0)
        self.assertTrue(manifest in parser.manifest_defaults)
        self.assertEquals(parser.manifest_defaults[manifest]['foo'], 'bar')
Пример #13
0
    def test_just_defaults(self):
        """Ensure a manifest with just a DEFAULT section exposes that data."""

        parser = ManifestParser()
        manifest = os.path.join(here, 'just-defaults.ini')
        parser.read(manifest)
        self.assertEqual(len(parser.tests), 0)
        self.assertTrue(manifest in parser.manifest_defaults)
        self.assertEquals(parser.manifest_defaults[manifest]['foo'], 'bar')
Пример #14
0
    def test_parent_defaults_include(self):
        parent_example = os.path.join(here, "parent", "include", "manifest.ini")
        parser = ManifestParser(manifests=(parent_example,))

        # global defaults should inherit all includes
        self.assertEqual(parser.get("name", top="data"), ["testFirst.js", "testSecond.js"])

        # include specific defaults should only inherit the actual include
        self.assertEqual(parser.get("name", disabled="YES"), ["testFirst.js"])
        self.assertEqual(parser.get("name", disabled="NO"), ["testSecond.js"])
Пример #15
0
    def test_sanity(self):
        """Ensure basic parser is sane"""

        parser = ManifestParser()
        mozmill_example = os.path.join(here, 'mozmill-example.ini')
        parser.read(mozmill_example)
        tests = parser.tests
        self.assertEqual(len(tests), len(file(mozmill_example).read().strip().splitlines()))

        # Ensure that capitalization and order aren't an issue:
        lines = ['[%s]' % test['name'] for test in tests]
        self.assertEqual(lines, file(mozmill_example).read().strip().splitlines())

        # Show how you select subsets of tests:
        mozmill_restart_example = os.path.join(here, 'mozmill-restart-example.ini')
        parser.read(mozmill_restart_example)
        restart_tests = parser.get(type='restart')
        self.assertTrue(len(restart_tests) < len(parser.tests))
        self.assertEqual(len(restart_tests), len(parser.get(manifest=mozmill_restart_example)))
        self.assertFalse([test for test in restart_tests
                          if test['manifest'] != os.path.join(here, 'mozmill-restart-example.ini')])
        self.assertEqual(parser.get('name', tags=['foo']),
                         ['restartTests/testExtensionInstallUninstall/test2.js',
                          'restartTests/testExtensionInstallUninstall/test1.js'])
        self.assertEqual(parser.get('name', foo='bar'),
                         ['restartTests/testExtensionInstallUninstall/test2.js'])
Пример #16
0
    def test_sanity(self):
        """Ensure basic parser is sane"""

        parser = ManifestParser()
        mozmill_example = os.path.join(here, "mozmill-example.ini")
        parser.read(mozmill_example)
        tests = parser.tests
        self.assertEqual(len(tests), len(file(mozmill_example).read().strip().splitlines()))

        # Ensure that capitalization and order aren't an issue:
        lines = ["[%s]" % test["name"] for test in tests]
        self.assertEqual(lines, file(mozmill_example).read().strip().splitlines())

        # Show how you select subsets of tests:
        mozmill_restart_example = os.path.join(here, "mozmill-restart-example.ini")
        parser.read(mozmill_restart_example)
        restart_tests = parser.get(type="restart")
        self.assertTrue(len(restart_tests) < len(parser.tests))
        self.assertEqual(len(restart_tests), len(parser.get(manifest=mozmill_restart_example)))
        self.assertFalse(
            [test for test in restart_tests if test["manifest"] != os.path.join(here, "mozmill-restart-example.ini")]
        )
        self.assertEqual(
            parser.get("name", tags=["foo"]),
            [
                "restartTests/testExtensionInstallUninstall/test2.js",
                "restartTests/testExtensionInstallUninstall/test1.js",
            ],
        )
        self.assertEqual(parser.get("name", foo="bar"), ["restartTests/testExtensionInstallUninstall/test2.js"])
Пример #17
0
    def test_verifyDirectory(self):

        directory = os.path.join(here, 'verifyDirectory')

        # correct manifest
        manifest_path = os.path.join(directory, 'verifyDirectory.ini')
        manifest = ManifestParser(manifests=(manifest_path, ))
        missing = manifest.verifyDirectory(directory, extensions=('.js', ))
        self.assertEqual(missing, (set(), set()))

        # manifest is missing test_1.js
        test_1 = os.path.join(directory, 'test_1.js')
        manifest_path = os.path.join(directory,
                                     'verifyDirectory_incomplete.ini')
        manifest = ManifestParser(manifests=(manifest_path, ))
        missing = manifest.verifyDirectory(directory, extensions=('.js', ))
        self.assertEqual(missing, (set(), set([test_1])))

        # filesystem is missing test_notappearinginthisfilm.js
        missing_test = os.path.join(directory,
                                    'test_notappearinginthisfilm.js')
        manifest_path = os.path.join(directory,
                                     'verifyDirectory_toocomplete.ini')
        manifest = ManifestParser(manifests=(manifest_path, ))
        missing = manifest.verifyDirectory(directory, extensions=('.js', ))
        self.assertEqual(missing, (set([missing_test]), set()))
Пример #18
0
    def test_manifest_list(self):
        """
        Ensure a manifest with just a DEFAULT section still returns
        itself from the manifests() method.
        """

        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)
Пример #19
0
    def test_manifest_list(self):
        """
        Ensure a manifest with just a DEFAULT section still returns
        itself from the manifests() method.
        """

        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)
Пример #20
0
    def test_parent_defaults_include(self):
        parent_example = os.path.join(here, 'parent', 'include',
                                      'manifest.ini')
        parser = ManifestParser(manifests=(parent_example, ))

        # global defaults should inherit all includes
        self.assertEqual(parser.get('name', top='data'),
                         ['testFirst.js', 'testSecond.js'])

        # include specific defaults should only inherit the actual include
        self.assertEqual(parser.get('name', disabled='YES'), ['testFirst.js'])
        self.assertEqual(parser.get('name', disabled='NO'), ['testSecond.js'])
Пример #21
0
    def test_parent_defaults_include(self):
        parent_example = os.path.join(here, 'parent', 'include', 'manifest.ini')
        parser = ManifestParser(manifests=(parent_example,))

        # global defaults should inherit all includes
        self.assertEqual(parser.get('name', top='data'),
                         ['testFirst.js', 'testSecond.js'])

        # include specific defaults should only inherit the actual include
        self.assertEqual(parser.get('name', disabled='YES'),
                         ['testFirst.js'])
        self.assertEqual(parser.get('name', disabled='NO'),
                         ['testSecond.js'])
    def test_manifest_ignore(self):
        """test manifest `ignore` parameter for ignoring directories"""

        stub = self.create_stub()
        try:
            ManifestParser.populate_directory_manifests([stub], filename="manifest.ini", ignore=("subdir",))
            parser = ManifestParser()
            parser.read(os.path.join(stub, "manifest.ini"))
            self.assertEqual([i["name"] for i in parser.tests], ["bar", "fleem", "foo"])
            self.assertFalse(os.path.exists(os.path.join(stub, "subdir", "manifest.ini")))
        except:
            raise
        finally:
            shutil.rmtree(stub)
Пример #23
0
    def test_manifest_ignore(self):
        """test manifest `ignore` parameter for ignoring directories"""

        stub = self.create_stub()
        try:
            ManifestParser.populate_directory_manifests([stub], filename='manifest.ini', ignore=('subdir',))
            parser = ManifestParser()
            parser.read(os.path.join(stub, 'manifest.ini'))
            self.assertEqual([i['name'] for i in parser.tests],
                             ['bar', 'fleem', 'foo'])
            self.assertFalse(os.path.exists(os.path.join(stub, 'subdir', 'manifest.ini')))
        except:
            raise
        finally:
            shutil.rmtree(stub)
Пример #24
0
    def test_install_from_manifest(self):

        temp_manifest = addon_stubs.generate_manifest()
        m = ManifestParser()
        m.read(temp_manifest)
        addons = m.get()
        # Obtain details of addons to install from the manifest
        addons_to_install = [self.am.addon_details(x['path'])['id'] for x in addons]

        self.am.install_from_manifest(temp_manifest)
        # Generate a list of addons installed in the profile
        addons_installed = [unicode(x[:-len('.xpi')]) for x in os.listdir(os.path.join(
                            self.profile.profile, 'extensions', 'staged'))]
        self.assertEqual(addons_installed.sort(), addons_to_install.sort())
        # Cleanup the temporary addon and manifest directories
        mozfile.rmtree(os.path.dirname(temp_manifest))
Пример #25
0
    def test_copy(self):
        """Test our ability to copy a set of manifests"""

        tempdir = tempfile.mkdtemp()
        include_example = os.path.join(here, 'include-example.ini')
        manifest = ManifestParser(manifests=(include_example, ))
        manifest.copy(tempdir)
        self.assertEqual(sorted(os.listdir(tempdir)),
                         ['fleem', 'include', 'include-example.ini'])
        self.assertEqual(sorted(os.listdir(os.path.join(tempdir, 'include'))),
                         ['bar.ini', 'crash-handling', 'flowers', 'foo.ini'])
        from_manifest = ManifestParser(manifests=(include_example, ))
        to_manifest = os.path.join(tempdir, 'include-example.ini')
        to_manifest = ManifestParser(manifests=(to_manifest, ))
        self.assertEqual(to_manifest.get('name'), from_manifest.get('name'))
        shutil.rmtree(tempdir)
Пример #26
0
    def test_include_handle_defaults_False(self):
        """
        Test that manifest_defaults and manifests() are correct even when
        handle_defaults is set to False.
        """
        manifest = os.path.join(here, 'include-example.ini')
        foo_path = os.path.join(here, 'include', 'foo.ini')

        parser = ManifestParser(manifests=(manifest,), handle_defaults=False,
                                rootdir=here)
        ancestor_ini = os.path.relpath(manifest, parser.rootdir)

        self.assertIn(manifest, parser.manifest_defaults)
        self.assertNotIn(foo_path, parser.manifest_defaults)
        self.assertIn((ancestor_ini, foo_path), parser.manifest_defaults)
        self.assertEqual(parser.manifest_defaults[manifest],
                         {
                             'foo': 'bar',
                             'here': here,
                         })
        self.assertEqual(parser.manifest_defaults[(ancestor_ini, foo_path)],
                         {
                             'here': os.path.join(here, 'include'),
                             'red': 'roses',
                             'blue': 'ocean',
                             'yellow': 'daffodils',
                         })
Пример #27
0
    def test_install_from_manifest(self):

        temp_manifest = addon_stubs.generate_manifest()
        m = ManifestParser()
        m.read(temp_manifest)
        addons = m.get()
        # Obtain details of addons to install from the manifest
        addons_to_install = [self.am.addon_details(x['path'])['id'] for x in addons]

        self.am.install_from_manifest(temp_manifest)
        # Generate a list of addons installed in the profile
        addons_installed = [unicode(x[:-len('.xpi')]) for x in os.listdir(os.path.join(
                            self.profile.profile, 'extensions', 'staged'))]
        self.assertEqual(addons_installed.sort(), addons_to_install.sort())
        # Cleanup the temporary addon and manifest directories
        mozfile.rmtree(os.path.dirname(temp_manifest))
Пример #28
0
    def test_include_handle_defaults_False(self):
        """
        Test that manifest_defaults and manifests() are correct even when
        handle_defaults is set to False.
        """
        manifest = os.path.join(here, "include-example.ini")
        foo_path = os.path.join(here, "include", "foo.ini")

        parser = ManifestParser(manifests=(manifest, ),
                                handle_defaults=False,
                                rootdir=here)
        ancestor_ini = os.path.relpath(manifest, parser.rootdir)

        self.assertIn(manifest, parser.manifest_defaults)
        self.assertNotIn(foo_path, parser.manifest_defaults)
        self.assertIn((ancestor_ini, foo_path), parser.manifest_defaults)
        self.assertEqual(
            parser.manifest_defaults[manifest],
            {
                "foo": "bar",
                "here": here,
            },
        )
        self.assertEqual(
            parser.manifest_defaults[(ancestor_ini, foo_path)],
            {
                "here": os.path.join(here, "include"),
                "red": "roses",
                "blue": "ocean",
                "yellow": "daffodils",
            },
        )
Пример #29
0
    def test_server_root(self):
        """
        Test server_root properly expands as an absolute path
        """
        server_example = os.path.join(here, "parent", "level_1", "level_2", "level_3", "level_3_server-root.ini")
        parser = ManifestParser(manifests=(server_example,))

        # A regular variable will inherit its value directly
        self.assertEqual(parser.get("name", **{"other-root": "../root"}), ["test_3"])

        # server-root will expand its value as an absolute path
        # we will not find anything for the original value
        self.assertEqual(parser.get("name", **{"server-root": "../root"}), [])

        # check that the path has expanded
        self.assertEqual(parser.get("server-root")[0], os.path.join(here, "parent", "root"))
Пример #30
0
 def test_path_override(self):
     """You can override the path in the section too.
     This shows that you can use a relative path"""
     path_example = os.path.join(here, 'path-example.ini')
     manifest = ManifestParser(manifests=(path_example, ))
     self.assertEqual(manifest.tests[0]['path'],
                      os.path.join(here, 'fleem'))
Пример #31
0
    def test_copy(self):
        """Test our ability to copy a set of manifests"""

        tempdir = tempfile.mkdtemp()
        include_example = os.path.join(here, "include-example.ini")
        manifest = ManifestParser(manifests=(include_example, ))
        manifest.copy(tempdir)
        self.assertEqual(sorted(os.listdir(tempdir)),
                         ["fleem", "include", "include-example.ini"])
        self.assertEqual(
            sorted(os.listdir(os.path.join(tempdir, "include"))),
            ["bar.ini", "crash-handling", "flowers", "foo.ini"],
        )
        from_manifest = ManifestParser(manifests=(include_example, ))
        to_manifest = os.path.join(tempdir, "include-example.ini")
        to_manifest = ManifestParser(manifests=(to_manifest, ))
        self.assertEqual(to_manifest.get("name"), from_manifest.get("name"))
        shutil.rmtree(tempdir)
Пример #32
0
 def test_path_from_fd(self):
     """
     Test paths are left untouched when manifest is a file-like object.
     """
     fp = StringIO("[section]\npath=fleem")
     manifest = ManifestParser(manifests=(fp, ))
     self.assertEqual(manifest.tests[0]['path'], 'fleem')
     self.assertEqual(manifest.tests[0]['relpath'], 'fleem')
     self.assertEqual(manifest.tests[0]['manifest'], None)
Пример #33
0
 def test_comments(self):
     """
     ensure comments work, see
     https://bugzilla.mozilla.org/show_bug.cgi?id=813674
     """
     comment_example = os.path.join(here, 'comment-example.ini')
     manifest = ManifestParser(manifests=(comment_example,))
     self.assertEqual(len(manifest.tests), 8)
     names = [i['name'] for i in manifest.tests]
     self.assertFalse('test_0202_app_launch_apply_update_dirlocked.js' in names)
Пример #34
0
    def test_server_root(self):
        """
        Test server_root properly expands as an absolute path
        """
        server_example = os.path.join(here, 'parent', 'level_1', 'level_2',
                                      'level_3', 'level_3_server-root.ini')
        parser = ManifestParser(manifests=(server_example, ))

        # A regular variable will inherit its value directly
        self.assertEqual(parser.get('name', **{'other-root': '../root'}),
                         ['test_3'])

        # server-root will expand its value as an absolute path
        # we will not find anything for the original value
        self.assertEqual(parser.get('name', **{'server-root': '../root'}), [])

        # check that the path has expanded
        self.assertEqual(
            parser.get('server-root')[0], os.path.join(here, 'parent', 'root'))
Пример #35
0
    def test_server_root(self):
        """
        Test server_root properly expands as an absolute path
        """
        server_example = os.path.join(here, 'parent', 'level_1', 'level_2',
                                      'level_3', 'level_3_server-root.ini')
        parser = ManifestParser(manifests=(server_example,))

        # A regular variable will inherit its value directly
        self.assertEqual(parser.get('name', **{'other-root': '../root'}),
                         ['test_3'])

        # server-root will expand its value as an absolute path
        # we will not find anything for the original value
        self.assertEqual(parser.get('name', **{'server-root': '../root'}), [])

        # check that the path has expanded
        self.assertEqual(parser.get('server-root')[0],
                         os.path.join(here, 'parent', 'root'))
Пример #36
0
    def test_defaults(self):

        default = os.path.join(here, "default-suppfiles.ini")
        parser = ManifestParser(manifests=(default, ))
        expected_supp_files = {
            "test7": "foo.js",
            "test8": "foo.js bar.js",
            "test9": "foo.js",
        }
        for test in parser.tests:
            expected = expected_supp_files[test["name"]]
            self.assertEqual(test["support-files"], expected)
Пример #37
0
    def test_parent_defaults(self):
        """
        Test downstream variables should overwrite upstream variables
        """
        parent_example = os.path.join(here, "parent", "level_1", "level_2", "level_3", "level_3_default.ini")
        parser = ManifestParser(manifests=(parent_example,))

        # Parent manifest test should not be included
        self.assertEqual(parser.get("name"), ["test_3"])
        self.assertEqual(
            [(test["name"], os.path.basename(test["manifest"])) for test in parser.tests],
            [("test_3", "level_3_default.ini")],
        )

        # DEFAULT values should be the ones from level 3
        self.assertEqual(parser.get("name", x="level_3"), ["test_3"])

        # Write the output to a manifest:
        buffer = StringIO()
        parser.write(fp=buffer, global_kwargs={"x": "level_3"})
        self.assertEqual(buffer.getvalue().strip(), "[DEFAULT]\nx = level_3\n\n[test_3]")
Пример #38
0
 def test_relative_path(self):
     """
     Relative test paths are correctly calculated.
     """
     relative_path = os.path.join(here, 'relative-path.ini')
     manifest = ManifestParser(manifests=(relative_path, ))
     self.assertEqual(manifest.tests[0]['path'],
                      os.path.join(os.path.dirname(here), 'fleem'))
     self.assertEqual(manifest.tests[0]['relpath'],
                      os.path.join('..', 'fleem'))
     self.assertEqual(manifest.tests[1]['relpath'],
                      os.path.join('..', 'testsSIBLING', 'example'))
Пример #39
0
    def test_defaults(self):

        default = os.path.join(here, 'default-suppfiles.ini')
        parser = ManifestParser(manifests=(default,))
        expected_supp_files = {
            'test1': 'foo.js # a comment',
            'test2': 'foo.js  bar.js ',
            'test3': 'foo.js # a comment',
        }
        for test in parser.tests:
            expected = expected_supp_files[test['name']]
            self.assertEqual(test['support-files'], expected)
Пример #40
0
 def test_relative_path(self):
     """
     Relative test paths are correctly calculated.
     """
     relative_path = os.path.join(here, "relative-path.ini")
     manifest = ManifestParser(manifests=(relative_path, ))
     self.assertEqual(manifest.tests[0]["path"],
                      os.path.join(os.path.dirname(here), "fleem"))
     self.assertEqual(manifest.tests[0]["relpath"],
                      os.path.join("..", "fleem"))
     self.assertEqual(manifest.tests[1]["relpath"],
                      os.path.join("..", "testsSIBLING", "example"))
Пример #41
0
 def test_subsuite_defaults(self):
     manifest = os.path.join(here, 'default-subsuite.ini')
     parser = ManifestParser(manifests=(manifest,), handle_defaults=False)
     expected_subsuites = {
         'test1': 'baz',
         'test2': 'foo',
     }
     defaults = parser.manifest_defaults[manifest]
     for test in parser.tests:
         value = combine_fields(defaults, test)
         self.assertEqual(expected_subsuites[value['name']],
                          value['subsuite'])
Пример #42
0
 def test_subsuite_defaults(self):
     manifest = os.path.join(here, "default-subsuite.ini")
     parser = ManifestParser(manifests=(manifest, ), handle_defaults=False)
     expected_subsuites = {
         "test1": "baz",
         "test2": "foo",
     }
     defaults = parser.manifest_defaults[manifest]
     for test in parser.tests:
         value = combine_fields(defaults, test)
         self.assertEqual(expected_subsuites[value["name"]],
                          value["subsuite"])
Пример #43
0
    def test_parent_inheritance(self):
        """
        Test parent manifest variable inheritance
        Specifically tests that inherited variables from parent includes
        properly propagate downstream
        """
        parent_example = os.path.join(here, 'parent', 'level_1', 'level_2',
                                      'level_3', 'level_3.ini')
        parser = ManifestParser(manifests=(parent_example,))

        # Parent manifest test should not be included
        self.assertEqual(parser.get('name'),
                         ['test_3'])
        self.assertEqual([(test['name'], os.path.basename(test['manifest'])) for test in parser.tests],
                         [('test_3', 'level_3.ini')])

        # DEFAULT values should be the ones from level 1
        self.assertEqual(parser.get('name', x='level_1'),
                         ['test_3'])

        # Write the output to a manifest:
        buffer = StringIO()
        parser.write(fp=buffer, global_kwargs={'x': 'level_1'})
        self.assertEqual(buffer.getvalue().strip(),
                         '[DEFAULT]\nx = level_1\n\n[test_3]\nsubsuite =')
    def test_convert_directory_manifests_in_place(self):
        """
        keep the manifests in place
        """

        stub = self.create_stub()
        try:
            ManifestParser.populate_directory_manifests([stub], filename='manifest.ini')
            self.assertEqual(sorted(os.listdir(stub)),
                             ['bar', 'fleem', 'foo', 'manifest.ini', 'subdir'])
            parser = ManifestParser()
            parser.read(os.path.join(stub, 'manifest.ini'))
            self.assertEqual([i['name'] for i in parser.tests],
                             ['subfile', 'bar', 'fleem', 'foo'])
            parser = ManifestParser()
            parser.read(os.path.join(stub, 'subdir', 'manifest.ini'))
            self.assertEqual(len(parser.tests), 1)
            self.assertEqual(parser.tests[0]['name'], 'subfile')
        except:
            raise
        finally:
            shutil.rmtree(stub)
Пример #45
0
    def test_parent_inheritance(self):
        """
        Test parent manifest variable inheritance
        Specifically tests that inherited variables from parent includes
        properly propagate downstream
        """
        parent_example = os.path.join(here, "parent", "level_1", "level_2", "level_3", "level_3.ini")
        parser = ManifestParser(manifests=(parent_example,))

        # Parent manifest test should not be included
        self.assertEqual(parser.get("name"), ["test_3"])
        self.assertEqual(
            [(test["name"], os.path.basename(test["manifest"])) for test in parser.tests], [("test_3", "level_3.ini")]
        )

        # DEFAULT values should be the ones from level 1
        self.assertEqual(parser.get("name", x="level_1"), ["test_3"])

        # Write the output to a manifest:
        buffer = StringIO()
        parser.write(fp=buffer, global_kwargs={"x": "level_1"})
        self.assertEqual(buffer.getvalue().strip(), "[DEFAULT]\nx = level_1\n\n[test_3]")
Пример #46
0
    def test_sanity(self):
        """Ensure basic parser is sane"""

        parser = ManifestParser()
        mozmill_example = os.path.join(here, "mozmill-example.ini")
        parser.read(mozmill_example)
        tests = parser.tests
        self.assertEqual(
            len(tests), len(open(mozmill_example).read().strip().splitlines()))

        # Ensure that capitalization and order aren't an issue:
        lines = ["[%s]" % test["name"] for test in tests]
        self.assertEqual(lines,
                         open(mozmill_example).read().strip().splitlines())

        # Show how you select subsets of tests:
        mozmill_restart_example = os.path.join(here,
                                               "mozmill-restart-example.ini")
        parser.read(mozmill_restart_example)
        restart_tests = parser.get(type="restart")
        self.assertTrue(len(restart_tests) < len(parser.tests))
        self.assertEqual(len(restart_tests),
                         len(parser.get(manifest=mozmill_restart_example)))
        self.assertFalse([
            test for test in restart_tests if test["manifest"] != os.path.join(
                here, "mozmill-restart-example.ini")
        ])
        self.assertEqual(
            parser.get("name", tags=["foo"]),
            [
                "restartTests/testExtensionInstallUninstall/test2.js",
                "restartTests/testExtensionInstallUninstall/test1.js",
            ],
        )
        self.assertEqual(
            parser.get("name", foo="bar"),
            ["restartTests/testExtensionInstallUninstall/test2.js"],
        )
Пример #47
0
    def test_parent_defaults(self):
        """
        Test downstream variables should overwrite upstream variables
        """
        parent_example = os.path.join(here, 'parent', 'level_1', 'level_2',
                                      'level_3', 'level_3_default.ini')
        parser = ManifestParser(manifests=(parent_example,))

        # Parent manifest test should not be included
        self.assertEqual(parser.get('name'),
                         ['test_3'])
        self.assertEqual([(test['name'], os.path.basename(test['manifest'])) for test in parser.tests],
                         [('test_3', 'level_3_default.ini')])

        # DEFAULT values should be the ones from level 3
        self.assertEqual(parser.get('name', x='level_3'),
                         ['test_3'])

        # Write the output to a manifest:
        buffer = StringIO()
        parser.write(fp=buffer, global_kwargs={'x': 'level_3'})
        self.assertEqual(buffer.getvalue().strip(),
                         '[DEFAULT]\nx = level_3\n\n[test_3]\nsubsuite =')
Пример #48
0
    def install_from_manifest(self, filepath):
        """
        Installs addons from a manifest
        :param filepath: path to the manifest of addons to install
        """
        try:
            from manifestparser import ManifestParser
        except ImportError:
            module_logger.critical(
                "Installing addons from manifest requires the"
                " manifestparser package to be installed.")
            raise

        manifest = ManifestParser()
        manifest.read(filepath)
        addons = manifest.get()

        for addon in addons:
            if '://' in addon['path'] or os.path.exists(addon['path']):
                self.install_from_path(addon['path'])
                continue

            # No path specified, try to grab it off AMO
            locale = addon.get('amo_locale', 'en_US')
            query = 'https://services.addons.mozilla.org/' + locale + '/firefox/api/' \
                    + AMO_API_VERSION + '/'
            if 'amo_id' in addon:
                # this query grabs information on the addon base on its id
                query += 'addon/' + addon['amo_id']
            else:
                # this query grabs information on the first addon returned from a search
                query += 'search/' + addon['name'] + '/default/1'
            install_path = AddonManager.get_amo_install_path(query)
            self.install_from_path(install_path)

        self.installed_manifests.append(filepath)
Пример #49
0
    def test_include_repeated(self):
        """
        Test that repeatedly included manifests are independent of each other.
        """
        include_example = os.path.join(here, 'include-example.ini')
        included_foo = os.path.join(here, 'include', 'foo.ini')

        # In the expected output, blue and yellow have the values from foo.ini
        # (ocean, submarine) instead of the ones from include-example.ini
        # (violets, daffodils), because the defaults in the included file take
        # precedence over the values from the parent.
        include_output = """[include/crash-handling]
foo = fleem

[fleem]
foo = bar

[include/flowers]
blue = ocean
foo = bar
red = roses
yellow = submarine

"""
        included_output = """[include/flowers]
blue = ocean
yellow = submarine

"""

        parser = ManifestParser(manifests=(include_example, included_foo),
                                rootdir=here)
        self.assertEqual(parser.get('name'),
                         ['crash-handling', 'fleem', 'flowers', 'flowers'])
        self.assertEqual([(test['name'], os.path.basename(test['manifest']))
                          for test in parser.tests],
                         [('crash-handling', 'bar.ini'),
                          ('fleem', 'include-example.ini'),
                          ('flowers', 'foo.ini'),
                          ('flowers', 'foo.ini')])
        self.check_included_repeat(parser, parser.tests[3], parser.tests[2],
                                   "%s%s" % (include_output, included_output))

        # Same tests, but with the load order of the manifests swapped.
        parser = ManifestParser(manifests=(included_foo, include_example),
                                rootdir=here)
        self.assertEqual(parser.get('name'),
                         ['flowers', 'crash-handling', 'fleem', 'flowers'])
        self.assertEqual([(test['name'], os.path.basename(test['manifest']))
                          for test in parser.tests],
                         [('flowers', 'foo.ini'),
                          ('crash-handling', 'bar.ini'),
                          ('fleem', 'include-example.ini'),
                          ('flowers', 'foo.ini')])
        self.check_included_repeat(parser, parser.tests[0], parser.tests[3],
                                   "%s%s" % (included_output, include_output))
Пример #50
0
    def test_update(self):
        """
        Test our ability to update tests from a manifest and a directory of
        files
        """

        # boilerplate
        tempdir = tempfile.mkdtemp()
        for i in range(10):
            file(os.path.join(tempdir, str(i)), 'w').write(str(i))

        # First, make a manifest:
        manifest = convert([tempdir])
        newtempdir = tempfile.mkdtemp()
        manifest_file = os.path.join(newtempdir, 'manifest.ini')
        file(manifest_file, 'w').write(manifest)
        manifest = ManifestParser(manifests=(manifest_file, ))
        self.assertEqual(manifest.get('name'), [str(i) for i in range(10)])

        # All of the tests are initially missing:
        self.assertEqual([i['name'] for i in manifest.missing()],
                         [str(i) for i in range(10)])

        # But then we copy one over:
        self.assertEqual(manifest.get('name', name='1'), ['1'])
        manifest.update(tempdir, name='1')
        self.assertEqual(sorted(os.listdir(newtempdir)), ['1', 'manifest.ini'])

        # Update that one file and copy all the "tests":
        file(os.path.join(tempdir, '1'), 'w').write('secret door')
        manifest.update(tempdir)
        self.assertEqual(
            sorted(os.listdir(newtempdir)),
            ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'manifest.ini'])
        self.assertEqual(
            file(os.path.join(newtempdir, '1')).read().strip(), 'secret door')

        # clean up:
        shutil.rmtree(tempdir)
        shutil.rmtree(newtempdir)
Пример #51
0
    def test_copy(self):
        """Test our ability to copy a set of manifests"""

        tempdir = tempfile.mkdtemp()
        include_example = os.path.join(here, 'include-example.ini')
        manifest = ManifestParser(manifests=(include_example,))
        manifest.copy(tempdir)
        self.assertEqual(sorted(os.listdir(tempdir)),
                         ['fleem', 'include', 'include-example.ini'])
        self.assertEqual(sorted(os.listdir(os.path.join(tempdir, 'include'))),
                         ['bar.ini', 'crash-handling', 'flowers', 'foo.ini'])
        from_manifest = ManifestParser(manifests=(include_example,))
        to_manifest = os.path.join(tempdir, 'include-example.ini')
        to_manifest = ManifestParser(manifests=(to_manifest,))
        self.assertEqual(to_manifest.get('name'), from_manifest.get('name'))
        shutil.rmtree(tempdir)
Пример #52
0
    def test_copy(self):
        """Test our ability to copy a set of manifests"""

        tempdir = tempfile.mkdtemp()
        include_example = os.path.join(here, "include-example.ini")
        manifest = ManifestParser(manifests=(include_example,))
        manifest.copy(tempdir)
        self.assertEqual(sorted(os.listdir(tempdir)), ["fleem", "include", "include-example.ini"])
        self.assertEqual(
            sorted(os.listdir(os.path.join(tempdir, "include"))), ["bar.ini", "crash-handling", "flowers", "foo.ini"]
        )
        from_manifest = ManifestParser(manifests=(include_example,))
        to_manifest = os.path.join(tempdir, "include-example.ini")
        to_manifest = ManifestParser(manifests=(to_manifest,))
        self.assertEqual(to_manifest.get("name"), from_manifest.get("name"))
        shutil.rmtree(tempdir)
    def test_convert_directory_manifests_in_place(self):
        """
        keep the manifests in place
        """

        stub = self.create_stub()
        try:
            ManifestParser.populate_directory_manifests([stub], filename="manifest.ini")
            self.assertEqual(sorted(os.listdir(stub)), ["bar", "fleem", "foo", "manifest.ini", "subdir"])
            parser = ManifestParser()
            parser.read(os.path.join(stub, "manifest.ini"))
            self.assertEqual([i["name"] for i in parser.tests], ["subfile", "bar", "fleem", "foo"])
            parser = ManifestParser()
            parser.read(os.path.join(stub, "subdir", "manifest.ini"))
            self.assertEqual(len(parser.tests), 1)
            self.assertEqual(parser.tests[0]["name"], "subfile")
        except:
            raise
        finally:
            shutil.rmtree(stub)
Пример #54
0
    def test_update(self):
        """
        Test our ability to update tests from a manifest and a directory of
        files
        """

        # boilerplate
        tempdir = tempfile.mkdtemp()
        for i in range(10):
            file(os.path.join(tempdir, str(i)), 'w').write(str(i))

        # First, make a manifest:
        manifest = convert([tempdir])
        newtempdir = tempfile.mkdtemp()
        manifest_file = os.path.join(newtempdir, 'manifest.ini')
        file(manifest_file,'w').write(manifest)
        manifest = ManifestParser(manifests=(manifest_file,))
        self.assertEqual(manifest.get('name'),
                         [str(i) for i in range(10)])

        # All of the tests are initially missing:
        self.assertEqual([i['name'] for i in manifest.missing()],
                         [str(i) for i in range(10)])

        # But then we copy one over:
        self.assertEqual(manifest.get('name', name='1'), ['1'])
        manifest.update(tempdir, name='1')
        self.assertEqual(sorted(os.listdir(newtempdir)),
                         ['1', 'manifest.ini'])

        # Update that one file and copy all the "tests":
        file(os.path.join(tempdir, '1'), 'w').write('secret door')
        manifest.update(tempdir)
        self.assertEqual(sorted(os.listdir(newtempdir)),
                         ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'manifest.ini'])
        self.assertEqual(file(os.path.join(newtempdir, '1')).read().strip(),
                         'secret door')

        # clean up:
        shutil.rmtree(tempdir)
        shutil.rmtree(newtempdir)
Пример #55
0
    def test_convert_directory_manifests_in_place(self):
        """
        keep the manifests in place
        """

        stub = self.create_stub()
        try:
            ManifestParser.populate_directory_manifests([stub], filename='manifest.ini')
            self.assertEqual(sorted(os.listdir(stub)),
                             ['bar', 'fleem', 'foo', 'manifest.ini', 'subdir'])
            parser = ManifestParser()
            parser.read(os.path.join(stub, 'manifest.ini'))
            self.assertEqual([i['name'] for i in parser.tests],
                             ['subfile', 'bar', 'fleem', 'foo'])
            parser = ManifestParser()
            parser.read(os.path.join(stub, 'subdir', 'manifest.ini'))
            self.assertEqual(len(parser.tests), 1)
            self.assertEqual(parser.tests[0]['name'], 'subfile')
        except:
            raise
        finally:
            shutil.rmtree(stub)
Пример #56
0
    def test_update(self):
        """
        Test our ability to update tests from a manifest and a directory of
        files
        """

        # boilerplate
        tempdir = create_realpath_tempdir()
        for i in range(10):
            file(os.path.join(tempdir, str(i)), 'w').write(str(i))

        # otherwise empty directory with a manifest file
        newtempdir = create_realpath_tempdir()
        manifest_file = os.path.join(newtempdir, 'manifest.ini')
        manifest_contents = str(convert([tempdir], relative_to=tempdir))
        with file(manifest_file, 'w') as f:
            f.write(manifest_contents)

        # get the manifest
        manifest = ManifestParser(manifests=(manifest_file,))

        # All of the tests are initially missing:
        paths = [str(i) for i in range(10)]
        self.assertEqual([i['name'] for i in manifest.missing()],
                         paths)

        # But then we copy one over:
        self.assertEqual(manifest.get('name', name='1'), ['1'])
        manifest.update(tempdir, name='1')
        self.assertEqual(sorted(os.listdir(newtempdir)),
                        ['1', 'manifest.ini'])

        # Update that one file and copy all the "tests":
        file(os.path.join(tempdir, '1'), 'w').write('secret door')
        manifest.update(tempdir)
        self.assertEqual(sorted(os.listdir(newtempdir)),
                        ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'manifest.ini'])
        self.assertEqual(file(os.path.join(newtempdir, '1')).read().strip(),
                        'secret door')

        # clean up:
        shutil.rmtree(tempdir)
        shutil.rmtree(newtempdir)
    def test_update(self):
        """
        Test our ability to update tests from a manifest and a directory of
        files
        """

        # boilerplate
        tempdir = create_realpath_tempdir()
        for i in range(10):
            file(os.path.join(tempdir, str(i)), "w").write(str(i))

        # otherwise empty directory with a manifest file
        newtempdir = create_realpath_tempdir()
        manifest_file = os.path.join(newtempdir, "manifest.ini")
        manifest_contents = str(convert([tempdir], relative_to=tempdir))
        with file(manifest_file, "w") as f:
            f.write(manifest_contents)

        # get the manifest
        manifest = ManifestParser(manifests=(manifest_file,))

        # All of the tests are initially missing:
        paths = [str(i) for i in range(10)]
        self.assertEqual([i["name"] for i in manifest.missing()], paths)

        # But then we copy one over:
        self.assertEqual(manifest.get("name", name="1"), ["1"])
        manifest.update(tempdir, name="1")
        self.assertEqual(sorted(os.listdir(newtempdir)), ["1", "manifest.ini"])

        # Update that one file and copy all the "tests":
        file(os.path.join(tempdir, "1"), "w").write("secret door")
        manifest.update(tempdir)
        self.assertEqual(
            sorted(os.listdir(newtempdir)), ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "manifest.ini"]
        )
        self.assertEqual(file(os.path.join(newtempdir, "1")).read().strip(), "secret door")

        # clean up:
        shutil.rmtree(tempdir)
        shutil.rmtree(newtempdir)
Пример #58
0
    def test_directory_to_manifest(self):
        """
        Test our ability to convert a static directory structure to a
        manifest.
        """

        # First, stub out a directory with files in it::
        def create_stub():
            directory = tempfile.mkdtemp()
            for i in 'foo', 'bar', 'fleem':
                file(os.path.join(directory, i), 'w').write(i)
            subdir = os.path.join(directory, 'subdir')
            os.mkdir(subdir)
            file(os.path.join(subdir, 'subfile'), 'w').write('baz')
            return directory
        stub = create_stub()
        self.assertTrue(os.path.exists(stub) and os.path.isdir(stub))

        # Make a manifest for it:
        self.assertEqual(convert([stub]),
                         """[bar]
[fleem]
[foo]
[subdir/subfile]""")
        shutil.rmtree(stub) # cleanup

        # Now do the same thing but keep the manifests in place:
        stub = create_stub()
        convert([stub], write='manifest.ini')
        self.assertEqual(sorted(os.listdir(stub)),
                         ['bar', 'fleem', 'foo', 'manifest.ini', 'subdir'])
        parser = ManifestParser()
        parser.read(os.path.join(stub, 'manifest.ini'))
        self.assertEqual([i['name'] for i in parser.tests],
                         ['subfile', 'bar', 'fleem', 'foo'])
        parser = ManifestParser()
        parser.read(os.path.join(stub, 'subdir', 'manifest.ini'))
        self.assertEqual(len(parser.tests), 1)
        self.assertEqual(parser.tests[0]['name'], 'subfile')
        shutil.rmtree(stub)
Пример #59
0
    def test_verifyDirectory(self):

        directory = os.path.join(here, 'verifyDirectory')

        # correct manifest
        manifest_path = os.path.join(directory, 'verifyDirectory.ini')
        manifest = ManifestParser(manifests=(manifest_path,))
        missing = manifest.verifyDirectory(directory, extensions=('.js',))
        self.assertEqual(missing, (set(), set()))

        # manifest is missing test_1.js
        test_1 = os.path.join(directory, 'test_1.js')
        manifest_path = os.path.join(directory, 'verifyDirectory_incomplete.ini')
        manifest = ManifestParser(manifests=(manifest_path,))
        missing = manifest.verifyDirectory(directory, extensions=('.js',))
        self.assertEqual(missing, (set(), set([test_1])))

        # filesystem is missing test_notappearinginthisfilm.js
        missing_test = os.path.join(directory, 'test_notappearinginthisfilm.js')
        manifest_path = os.path.join(directory, 'verifyDirectory_toocomplete.ini')
        manifest = ManifestParser(manifests=(manifest_path,))
        missing = manifest.verifyDirectory(directory, extensions=('.js',))
        self.assertEqual(missing, (set([missing_test]), set()))
Пример #60
0
    def test_include(self):
        """Illustrate how include works"""

        include_example = os.path.join(here, 'include-example.ini')
        parser = ManifestParser(manifests=(include_example,))

        # All of the tests should be included, in order:
        self.assertEqual(parser.get('name'),
                         ['crash-handling', 'fleem', 'flowers'])
        self.assertEqual([(test['name'], os.path.basename(test['manifest'])) for test in parser.tests],
                         [('crash-handling', 'bar.ini'), ('fleem', 'include-example.ini'), ('flowers', 'foo.ini')])


        # The manifests should be there too:
        self.assertEqual(len(parser.manifests()), 3)

        # We already have the root directory:
        self.assertEqual(here, parser.rootdir)


        # DEFAULT values should persist across includes, unless they're
        # overwritten.  In this example, include-example.ini sets foo=bar, but
        # it's overridden to fleem in bar.ini
        self.assertEqual(parser.get('name', foo='bar'),
                         ['fleem', 'flowers'])
        self.assertEqual(parser.get('name', foo='fleem'),
                         ['crash-handling'])

        # Passing parameters in the include section allows defining variables in
        #the submodule scope:
        self.assertEqual(parser.get('name', tags=['red']),
                         ['flowers'])

        # However, this should be overridable from the DEFAULT section in the
        # included file and that overridable via the key directly connected to
        # the test:
        self.assertEqual(parser.get(name='flowers')[0]['blue'],
                         'ocean')
        self.assertEqual(parser.get(name='flowers')[0]['yellow'],
                         'submarine')

        # You can query multiple times if you need to:
        flowers = parser.get(foo='bar')
        self.assertEqual(len(flowers), 2)

        # Using the inverse flag should invert the set of tests returned:
        self.assertEqual(parser.get('name', inverse=True, tags=['red']),
                         ['crash-handling', 'fleem'])

        # All of the included tests actually exist:
        self.assertEqual([i['name'] for i in parser.missing()], [])

        # Write the output to a manifest:
        buffer = StringIO()
        parser.write(fp=buffer, global_kwargs={'foo': 'bar'})
        self.assertEqual(buffer.getvalue().strip(),
                         '[DEFAULT]\nfoo = bar\n\n[fleem]\n\n[include/flowers]\nblue = ocean\nred = roses\nyellow = submarine')