Пример #1
0
    def setUp(self):
        self.logger = mozlog.getLogger('mozprofile.addons')
        self.logger.setLevel(mozlog.ERROR)

        self.profile = mozprofile.profile.Profile()
        self.am = self.profile.addon_manager

        self.profile_path = self.profile.profile
        self.tmpdir = tempfile.mkdtemp()
        self.addCleanup(mozfile.remove, self.tmpdir)
Пример #2
0
    def setUp(self):
        self.logger = mozlog.getLogger('mozprofile.addons')
        self.logger.setLevel(mozlog.ERROR)

        self.profile = mozprofile.profile.Profile()
        self.am = self.profile.addon_manager

        self.profile_path = self.profile.profile
        self.tmpdir = tempfile.mkdtemp()
        self.addCleanup(mozfile.remove, self.tmpdir)
Пример #3
0
    def test_logger_defaults(self):
        """Tests the default logging format and behavior."""

        default_logger = mozlog.getLogger('default.logger')
        self.assertEqual(default_logger.name, 'default.logger')
        self.assertEqual(len(default_logger.handlers), 1)
        self.assertTrue(isinstance(default_logger.handlers[0],
                                   mozlog.StreamHandler))

        f = mozfile.NamedTemporaryFile()
        list_logger = mozlog.getLogger('file.logger',
                                       handler=mozlog.FileHandler(f.name))
        self.assertEqual(len(list_logger.handlers), 1)
        self.assertTrue(isinstance(list_logger.handlers[0],
                                   mozlog.FileHandler))
        f.close()

        self.assertRaises(ValueError, mozlog.getLogger,
                          'file.logger', handler=ListHandler())
Пример #4
0
    def test_logger_defaults(self):
        """Tests the default logging format and behavior."""

        default_logger = mozlog.getLogger('default.logger')
        self.assertEqual(default_logger.name, 'default.logger')
        self.assertEqual(len(default_logger.handlers), 1)
        self.assertTrue(isinstance(default_logger.handlers[0],
                                   mozlog.StreamHandler))

        f = mozfile.NamedTemporaryFile()
        list_logger = mozlog.getLogger('file.logger',
                                       handler=mozlog.FileHandler(f.name))
        self.assertEqual(len(list_logger.handlers), 1)
        self.assertTrue(isinstance(list_logger.handlers[0],
                                   mozlog.FileHandler))
        f.close()

        self.assertRaises(ValueError, mozlog.getLogger,
                          'file.logger', handler=ListHandler())
Пример #5
0
 def test_timestamps(self):
     """Verifies that timestamps are included when asked for."""
     log_name = 'test'
     handler = ListHandler()
     handler.setFormatter(mozlog.MozFormatter())
     log = mozlog.getLogger(log_name, handler=handler)
     log.info('no timestamp')
     self.assertTrue(handler.messages[-1].startswith('%s ' % log_name))
     handler.setFormatter(mozlog.MozFormatter(include_timestamp=True))
     log.info('timestamp')
     # Just verify that this raises no exceptions.
     datetime.datetime.strptime(handler.messages[-1][:23],
                                '%Y-%m-%d %H:%M:%S,%f')
Пример #6
0
 def test_timestamps(self):
     """Verifies that timestamps are included when asked for."""
     log_name = 'test'
     handler = ListHandler()
     handler.setFormatter(mozlog.MozFormatter())
     log = mozlog.getLogger(log_name, handler=handler)
     log.info('no timestamp')
     self.assertTrue(handler.messages[-1].startswith('%s ' % log_name))
     handler.setFormatter(mozlog.MozFormatter(include_timestamp=True))
     log.info('timestamp')
     # Just verify that this raises no exceptions.
     datetime.datetime.strptime(handler.messages[-1][:23],
                                '%Y-%m-%d %H:%M:%S,%f')
Пример #7
0
import shutil
import sys
import tempfile
import urllib2
import zipfile
from xml.dom import minidom

import mozfile
from mozlog.unstructured import getLogger

# Needed for the AMO's rest API -
# https://developer.mozilla.org/en/addons.mozilla.org_%28AMO%29_API_Developers%27_Guide/The_generic_AMO_API
AMO_API_VERSION = "1.5"

# Logger for 'mozprofile.addons' module
module_logger = getLogger(__name__)


class AddonFormatError(Exception):
    """Exception for not well-formed add-on manifest files"""


class AddonManager(object):
    """
    Handles all operations regarding addons in a profile including:
    installing and cleaning addons
    """

    def __init__(self, profile, restore=True):
        """
        :param profile: the path to the profile for which we install addons
Пример #8
0
#!/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, unittest, subprocess, tempfile, shutil, urlparse, zipfile, StringIO
import mozcrash
import mozhttpd
import mozlog.unstructured as mozlog

# Make logs go away
log = mozlog.getLogger("mozcrash", handler=mozlog.FileHandler(os.devnull))

def popen_factory(stdouts):
    """
    Generate a class that can mock subprocess.Popen. |stdouts| is an iterable that
    should return an iterable for the stdout of each process in turn.
    """
    class mock_popen(object):
        def __init__(self, args, *args_rest, **kwargs):
            self.stdout = stdouts.next()
            self.returncode = 0

        def wait(self):
            return 0

        def communicate(self):
            return (self.stdout.next(), "")

    return mock_popen
Пример #9
0
# You can obtain one at http://mozilla.org/MPL/2.0/.

import os
import unittest
import subprocess
import tempfile
import shutil
import urlparse
import zipfile
import StringIO
import mozcrash
import mozhttpd
import mozlog.unstructured as mozlog

# Make logs go away
log = mozlog.getLogger("mozcrash", handler=mozlog.FileHandler(os.devnull))


def popen_factory(stdouts):
    """
    Generate a class that can mock subprocess.Popen. |stdouts| is an iterable that
    should return an iterable for the stdout of each process in turn.
    """
    class mock_popen(object):

        def __init__(self, args, *args_rest, **kwargs):
            self.stdout = stdouts.next()
            self.returncode = 0

        def wait(self):
            return 0