Exemplo n.º 1
0
#  license you chose for the specific language governing permissions and
#  limitations under that license.
#

import codecs
utf_8_decode = codecs.utf_8_decode
import datetime
from io import UnsupportedOperation
import os
import select
import struct
import sys
import zlib

from extras import safe_hasattr, try_imports
builtins = try_imports(['__builtin__', 'builtins'])

import subunit
import subunit.iso8601 as iso8601

__all__ = [
    'ByteStreamToStreamResult',
    'StreamResultToBytes',
]

SIGNATURE = b'\xb3'
FMT_8 = '>B'
FMT_16 = '>H'
FMT_24 = '>HB'
FMT_32 = '>I'
FMT_TIMESTAMP = '>II'
Exemplo n.º 2
0
"""python -m testtools.run testspec [testspec...]

Run some tests with the testtools extended API.

For instance, to run the testtools test suite.
 $ python -m testtools.run testtools.tests.test_suite
"""

import argparse
from functools import partial
import os.path
import sys

from extras import safe_hasattr, try_imports
# To let setup.py work, make this a conditional import.
unittest = try_imports(['unittest2', 'unittest'])

from testtools import TextTestResult
from testtools.compat import unicode_output_stream
from testtools.testsuite import filter_by_ids, iterate_tests, sorted_tests

defaultTestLoader = unittest.defaultTestLoader
defaultTestLoaderCls = unittest.TestLoader
have_discover = True
# This shouldn't really be public - its legacy.  Try to set it if we can, and
# if we can't (during installs before unittest2 is installed) just stub it out
# to None.
discover_impl = getattr(unittest, 'loader', None)

# Kept for API compatibility, but no longer used.
BUFFEROUTPUT = ""
Exemplo n.º 3
0
#  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
#  license you chose for the specific language governing permissions and
#  limitations under that license.
#

import codecs
utf_8_decode = codecs.utf_8_decode
import datetime
from io import UnsupportedOperation
import os
import select
import struct
import zlib

from extras import safe_hasattr, try_imports
builtins = try_imports(['__builtin__', 'builtins'])

import subunit
import subunit.iso8601 as iso8601

__all__ = [
    'ByteStreamToStreamResult',
    'StreamResultToBytes',
    ]

SIGNATURE = b'\xb3'
FMT_8  = '>B'
FMT_16 = '>H'
FMT_24 = '>HB'
FMT_32 = '>I'
FMT_TIMESTAMP = '>II'
Exemplo n.º 4
0
__metaclass__ = type
__all__ = [
  'ConcurrentTestSuite',
  'ConcurrentStreamTestSuite',
  'filter_by_ids',
  'iterate_tests',
  'sorted_tests',
  ]

import sys
import threading
import unittest

from extras import safe_hasattr, try_imports

Queue = try_imports(['Queue.Queue', 'queue.Queue'])

import testtools


def iterate_tests(test_suite_or_case):
    """Iterate through all of the test cases in 'test_suite_or_case'."""
    try:
        suite = iter(test_suite_or_case)
    except TypeError:
        yield test_suite_or_case
    else:
        for test in suite:
            for subtest in iterate_tests(test):
                yield subtest
Exemplo n.º 5
0
 def test_existing_module(self):
     # try_imports('thing', foo) imports 'thing' and returns it if it's a
     # module that exists.
     result = try_imports(['os'], object())
     import os
     self.assertThat(result, Is(os))
Exemplo n.º 6
0
 def test_nonexistent_submodule(self):
     # try_imports('thing.another', foo) imports 'thing' and returns foo if
     # 'another' doesn't exist.
     marker = object()
     result = try_imports(['os.doesntexist'], marker)
     self.assertThat(result, Is(marker))
 def test_existing_submodule(self):
     # try_imports('thing.another', foo) imports 'thing' and returns it if
     # it's a module that exists.
     result = try_imports(['os.path'], object())
     import os
     self.assertThat(result, Is(os.path))
Exemplo n.º 8
0
# compliance with one of these two licences.
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
# license you chose for the specific language governing permissions and
# limitations under that license.

"""The crcache local data store.

This store uses a simple python ndb for storing active/pooled instance
metadata.
"""

from extras import try_imports
dbm = try_imports(['dbm', 'dbm.ndbm'])
import os.path

from cr_cache.store import AbstractStore

class Store(AbstractStore):
    """General store for most crcache operations.

    Stores data in ~/.cache/crcache/state.db.
    Updates may be batched depending on the dbm implementation, with a lock
    kept in state.lck.
    """

    def __init__(self):
        self.dbm_path = os.path.expanduser('~/.cache/crcache/state')
        self.dbm_lock = os.path.expanduser('~/.cache/crcache/state.lck')
 def test_fallback(self):
     result = try_imports(['doesntexist', 'os'])
     import os
     self.assertThat(result, Is(os))
Exemplo n.º 10
0
 def test_existing_module(self):
     # try_imports('thing', foo) imports 'thing' and returns it if it's a
     # module that exists.
     result = try_imports(['os'], object())
     import os
     self.assertThat(result, Is(os))
Exemplo n.º 11
0
 def test_doesnt_exist(self):
     # try_imports('thing', foo) returns foo if 'thing' doesn't exist.
     marker = object()
     result = try_imports(['doesntexist'], marker)
     self.assertThat(result, Is(marker))
Exemplo n.º 12
0
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.


import extras

mock = extras.try_imports(["unittest.mock", "mock"], None)
import testtools

from fixtures import MockPatch, MockPatchMultiple, MockPatchObject


class Foo(object):
    def bar(self):
        return self


def mocking_bar(self):
    return "mocked!"


class TestMockPatch(testtools.TestCase):
Exemplo n.º 13
0
#
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
#    not use this file except in compliance with the License. You may obtain
#    a copy of the License at
#
#         http://www.apache.org/licenses/LICENSE-2.0
#
#    Unless required by applicable law or agreed to in writing, software
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.


import extras
mock = extras.try_imports(['unittest.mock', 'mock'], None)
import testtools

from fixtures import (
    MockPatch,
    MockPatchMultiple,
    MockPatchObject,
)


class Foo(object):
    def bar(self):
        return self


def mocking_bar(self):
Exemplo n.º 14
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import copy
import os
import re
import struct
import time
from uuid import uuid4
import extras

OrderedDict = extras.try_imports(['collections.OrderedDict',
                                  'ordereddict.OrderedDict'])


EMPTY_GIT_REF = '0' * 40  # git sha of all zeros, used during creates/deletes

MERGER_MERGE = 1          # "git merge"
MERGER_MERGE_RESOLVE = 2  # "git merge -s resolve"
MERGER_CHERRY_PICK = 3    # "git cherry-pick"

MERGER_MAP = {
    'merge': MERGER_MERGE,
    'merge-resolve': MERGER_MERGE_RESOLVE,
    'cherry-pick': MERGER_CHERRY_PICK,
}

PRECEDENCE_NORMAL = 0
Exemplo n.º 15
0
 def test_nonexistent_submodule(self):
     # try_imports('thing.another', foo) imports 'thing' and returns foo if
     # 'another' doesn't exist.
     marker = object()
     result = try_imports(['os.doesntexist'], marker)
     self.assertThat(result, Is(marker))
Exemplo n.º 16
0
    ]

import copy
import functools
import itertools
import sys
import types
import warnings

from extras import (
    safe_hasattr,
    try_import,
    try_imports,
    )
# To let setup.py work, make this a conditional import.
unittest = try_imports(['unittest2', 'unittest'])

from testtools import (
    content,
    )
from testtools.compat import (
    advance_iterator,
    reraise,
    )
from testtools.matchers import (
    Annotate,
    Contains,
    Equals,
    MatchesAll,
    MatchesException,
    MismatchError,
Exemplo n.º 17
0
 def test_fallback_submodule(self):
     result = try_imports(['os.doesntexist', 'os.path'])
     import os
     self.assertThat(result, Is(os.path))
Exemplo n.º 18
0
 def test_fallback(self):
     result = try_imports(['doesntexist', 'os'])
     import os
     self.assertThat(result, Is(os))
Exemplo n.º 19
0
    'reraise',
    'unicode_output_stream',
]

import codecs
import io
import locale
import os
import re
import sys
import traceback
import unicodedata

from extras import try_import, try_imports

BytesIO = try_imports(['StringIO.StringIO', 'io.BytesIO'])
StringIO = try_imports(['StringIO.StringIO', 'io.StringIO'])
# To let setup.py work, make this a conditional import.
linecache = try_import('linecache2')

try:
    from testtools import _compat2x as _compat
except SyntaxError:
    from testtools import _compat3x as _compat

reraise = _compat.reraise

__u_doc = """A function version of the 'u' prefix.

This is needed becayse the u prefix is not usable in Python 3 but is required
in Python 2 to get a unicode object.
Exemplo n.º 20
0
 def test_existing_submodule(self):
     # try_imports('thing.another', foo) imports 'thing' and returns it if
     # it's a module that exists.
     result = try_imports(['os.path'], object())
     import os
     self.assertThat(result, Is(os.path))
Exemplo n.º 21
0
import codecs

utf_8_decode = codecs.utf_8_decode
import datetime
import select
import struct
import sys
import zlib

import extras
import iso8601

import pysubunit

builtins = extras.try_imports(['__builtin__', 'builtins'])

__all__ = [
    'ByteStreamToStreamResult',
    'StreamResultToBytes',
]

SIGNATURE = b'\xb3'
FMT_8 = '>B'
FMT_16 = '>H'
FMT_24 = '>HB'
FMT_32 = '>I'
FMT_TIMESTAMP = '>II'
FLAG_TEST_ID = 0x0800
FLAG_ROUTE_CODE = 0x0400
FLAG_TIMESTAMP = 0x0200
Exemplo n.º 22
0
 def test_fallback_submodule(self):
     result = try_imports(['os.doesntexist', 'os.path'])
     import os
     self.assertThat(result, Is(os.path))
Exemplo n.º 23
0
# compliance with one of these two licences.
#
# Unless required by applicable law or agreed to in writing, software
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
# license you chose for the specific language governing permissions and
# limitations under that license.
"""The test command that test repository knows how to run."""

from extras import (
    try_import,
    try_imports,
)

from collections import defaultdict
ConfigParser = try_imports(['ConfigParser', 'configparser'])
import io
import itertools
import operator
import os.path
import re
import subprocess
import sys
import tempfile
import multiprocessing
from textwrap import dedent

from fixtures import Fixture
v2 = try_import('subunit.v2')

from testrepository import results
Exemplo n.º 24
0
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import extras

import fixtures

mock = extras.try_imports(['unittest.mock', 'mock'], None)
mock_default = extras.try_imports(
    ['unittest.mock.DEFAULT', 'mock.DEFAULT'], None)


class _Base(fixtures.Fixture):
    def _setUp(self):
        _p = self._get_p()
        self.addCleanup(_p.stop)
        self.mock = _p.start()


class MockPatchObject(_Base):
    """Deal with code around mock."""

    def __init__(self, obj, attr, new=mock_default, **kwargs):
Exemplo n.º 25
0
    'ConcurrentTestSuite',
    'ConcurrentStreamTestSuite',
    'filter_by_ids',
    'iterate_tests',
    'sorted_tests',
]

from collections import Counter
from pprint import pformat
import sys
import threading
import unittest

from extras import safe_hasattr, try_imports
# This is just to let setup.py work, as testtools is imported in setup.py.
unittest2 = try_imports(['unittest2', 'unittest'])
Queue = try_imports(['Queue.Queue', 'queue.Queue'])

import testtools


def iterate_tests(test_suite_or_case):
    """Iterate through all of the test cases in 'test_suite_or_case'."""
    try:
        suite = iter(test_suite_or_case)
    except TypeError:
        yield test_suite_or_case
    else:
        for test in suite:
            for subtest in iterate_tests(test):
                yield subtest
Exemplo n.º 26
0
    'reraise',
    'unicode_output_stream',
    ]

import codecs
import linecache
import locale
import os
import re
import sys
import traceback
import unicodedata

from extras import try_imports

BytesIO = try_imports(['StringIO.StringIO', 'io.BytesIO'])
StringIO = try_imports(['StringIO.StringIO', 'io.StringIO'])

try:
    from testtools import _compat2x as _compat
except SyntaxError:
    from testtools import _compat3x as _compat

reraise = _compat.reraise


__u_doc = """A function version of the 'u' prefix.

This is needed becayse the u prefix is not usable in Python 3 but is required
in Python 2 to get a unicode object.
Exemplo n.º 27
0
__all__ = [
    'ConcurrentTestSuite',
    'ConcurrentStreamTestSuite',
    'filter_by_ids',
    'iterate_tests',
    'sorted_tests',
]

from pprint import pformat
import sys
import threading
import unittest

from extras import safe_hasattr, try_imports
# This is just to let setup.py work, as testtools is imported in setup.py.
unittest2 = try_imports(['unittest2', 'unittest'])
Queue = try_imports(['Queue.Queue', 'queue.Queue'])

import testtools


def iterate_tests(test_suite_or_case):
    """Iterate through all of the test cases in 'test_suite_or_case'."""
    try:
        suite = iter(test_suite_or_case)
    except TypeError:
        yield test_suite_or_case
    else:
        for test in suite:
            for subtest in iterate_tests(test):
                yield subtest
Exemplo n.º 28
0

import argparse
import daemon
import extras
import os
import signal
import sys
import time
import yaml

from turbo_hipster import worker_server

# as of python-daemon 1.6 it doesn't bundle pidlockfile anymore
# instead it depends on lockfile-0.9.1 which uses pidfile.
PID_FILE_MODULE = extras.try_imports(['daemon.pidlockfile', 'daemon.pidfile'])


def setup_server(args):

    with open(args.config, 'r') as config_stream:
        config = yaml.safe_load(config_stream)

    if not config['debug_log']:
        # NOTE(mikal): debug logging _must_ be enabled for the log writing
        # in lib.utils.execute_to_log to work correctly.
        raise Exception('Debug log not configured')

    server = worker_server.Server(config)
    server.setup_logging(config['debug_log'])
Exemplo n.º 29
0
__metaclass__ = type
__all__ = [
    'ConcurrentTestSuite',
    'ConcurrentStreamTestSuite',
    'filter_by_ids',
    'iterate_tests',
    'sorted_tests',
]

import sys
import threading
import unittest

from extras import safe_hasattr, try_imports

Queue = try_imports(['Queue.Queue', 'queue.Queue'])

import testtools


def iterate_tests(test_suite_or_case):
    """Iterate through all of the test cases in 'test_suite_or_case'."""
    try:
        suite = iter(test_suite_or_case)
    except TypeError:
        yield test_suite_or_case
    else:
        for test in suite:
            for subtest in iterate_tests(test):
                yield subtest
Exemplo n.º 30
0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under these licenses is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
# license you chose for the specific language governing permissions and
# limitations under that license.

"""The test command that test repository knows how to run."""

from extras import (
    try_import,
    try_imports,
    )

from collections import defaultdict
ConfigParser = try_imports(['ConfigParser', 'configparser'])
import io
import itertools
import operator
import os.path
import re
import subprocess
import sys
import tempfile
import multiprocessing
from textwrap import dedent

from fixtures import Fixture
from subunit import ByteStreamToStreamResult

from testrepository import results
Exemplo n.º 31
0
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import extras

import fixtures

mock = extras.try_imports(['mock', 'unittest.mock'], None)
mock_default = extras.try_imports(['mock.DEFAULT', 'unittest.mock.DEFAULT'],
                                  None)


class _Base(fixtures.Fixture):
    def _setUp(self):
        _p = self._get_p()
        self.addCleanup(_p.stop)
        self.mock = _p.start()


class MockPatchObject(_Base):
    """Deal with code around mock."""
    def __init__(self, obj, attr, new=mock_default, **kwargs):
        super(MockPatchObject, self).__init__()
Exemplo n.º 32
0
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import argparse
import daemon
import errno
import extras

# as of python-daemon 1.6 it doesn't bundle pidlockfile anymore
# instead it depends on lockfile-0.9.1 which uses pidfile.
pid_file_module = extras.try_imports(['daemon.pidlockfile', 'daemon.pidfile'])

import logging.config
import os
import sys
import signal
import traceback
import threading

import nodepool.builder
import nodepool.cmd
import nodepool.nodepool
import nodepool.webapp


def stack_dump_handler(signum, frame):
Exemplo n.º 33
0
 def test_doesnt_exist(self):
     # try_imports('thing', foo) returns foo if 'thing' doesn't exist.
     marker = object()
     result = try_imports(['doesntexist'], marker)
     self.assertThat(result, Is(marker))
Exemplo n.º 34
0
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

import argparse
import ConfigParser
import daemon
import extras

# as of python-daemon 1.6 it doesn't bundle pidlockfile anymore
# instead it depends on lockfile-0.9.1 which uses pidfile.
pid_file_module = extras.try_imports(['daemon.pidlockfile', 'daemon.pidfile'])

import logging
import logging.config
import os
import sys
import signal
import traceback

import gear

# No zuul imports here because they pull in paramiko which must not be
# imported until after the daemonization.
# https://github.com/paramiko/paramiko/issues/59

Exemplo n.º 35
0
#

import codecs

utf_8_decode = codecs.utf_8_decode
import datetime
from io import UnsupportedOperation
import os
import select
import struct
import sys
import zlib

from extras import safe_hasattr, try_imports

builtins = try_imports(["__builtin__", "builtins"])

import subunit
import subunit.iso8601 as iso8601

__all__ = ["ByteStreamToStreamResult", "StreamResultToBytes"]

SIGNATURE = b"\xb3"
FMT_8 = ">B"
FMT_16 = ">H"
FMT_24 = ">HB"
FMT_32 = ">I"
FMT_TIMESTAMP = ">II"
FLAG_TEST_ID = 0x0800
FLAG_ROUTE_CODE = 0x0400
FLAG_TIMESTAMP = 0x0200