How to use the testfixtures.compat.basestring function in testfixtures

To help you get started, we’ve selected a few testfixtures examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Simplistix / testfixtures / testfixtures / tempdirectory.py View on Github external
def _join(self, name):
        # make things platform independent
        if isinstance(name, basestring):
            name = name.split('/')
        relative = os.sep.join(name).rstrip(os.sep)
        if relative.startswith(os.sep):
            if relative.startswith(self.path):
                return relative
            raise ValueError(
                'Attempt to read or write outside the temporary Directory'
                )
        return os.path.join(self.path, relative)
github Simplistix / testfixtures / testfixtures / tempdirectory.py View on Github external
into bytes.

        :param filepath: The path to the file to create, which can be:

                         * A tuple of strings.

                         * A forward-slash separated string.

        :param data: A string containing the data to be written.

        :param encoding: The encoding to be used if data is not bytes. Should
                         not be passed if data is already bytes.

        :returns: The full path of the file written.
        """
        if isinstance(filepath, basestring):
            filepath = filepath.split('/')
        if len(filepath) > 1:
            dirpath = self._join(filepath[:-1])
            if not os.path.exists(dirpath):
                os.makedirs(dirpath)
        thepath = self._join(filepath)
        encoding = encoding or self.encoding
        if encoding is not None:
            data = data.encode(encoding)
        with open(thepath, 'wb') as f:
            f.write(data)
        return thepath
github Simplistix / testfixtures / testfixtures / comparison.py View on Github external
def __init__(self,
                 object_or_type,
                 attribute_dict=None,
                 strict=True,
                 **attributes):
        if attributes:
            if attribute_dict is None:
                attribute_dict = attributes
            else:
                attribute_dict.update(attributes)
        if isinstance(object_or_type, basestring):
            container, method, name, c = resolve(object_or_type)
            if c is not_there:
                raise AttributeError(
                    '%r could not be resolved' % object_or_type
                )
        elif isinstance(object_or_type, (ClassType, type)):
            c = object_or_type
        else:
            c = object_or_type.__class__
            if attribute_dict is None:
                attribute_dict = _extract_attrs(object_or_type)
        self.c = c
        self.v = attribute_dict
        self.strict = strict
github Simplistix / testfixtures / testfixtures / popen.py View on Github external
def shell_join(command):
    if not isinstance(command, basestring):
        command = " ".join(pipes.quote(part) for part in command)
    return command
github Simplistix / testfixtures / testfixtures / comparison.py View on Github external
# must be an old-style class object in Python 2!
        return (obj, )
    mro = getattr(class_, '__mro__', None)
    if mro is None:
        # instance of old-style class in Python 2!
        return (class_, )
    return mro


def _shared_mro(x, y):
    y_mro = set(_mro(y))
    for class_ in _mro(x):
        if class_ in y_mro:
            yield class_

_unsafe_iterables = basestring, dict


class CompareContext(object):

    x_label = y_label = None

    def __init__(self, options):
        self.registries = []
        comparers = options.pop('comparers', None)
        if comparers:
            self.registries.append(comparers)
        self.registries.append(_registry)

        self.recursive = options.pop('recursive', True)
        self.strict = options.pop('strict', False)
        self.ignore_eq = options.pop('ignore_eq', False)