1
  Y   ˆl–Ü4ý( ©”u( 	•íÀà™S�ÿ�þ\,£Y¹DGÃ Â�ÏÂ„ÍÁ_ŠI|¥�+Wé3ž¯a–Ãa¾”Ò~êq@3p ¸ÛJbÑ¿Á ?÷     # Copyright (C) 2008-2012 Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

import os
import sys


from .... import (
    bedding,
    controldir,
    errors,
    osutils,
    revisionspec,
    tests,
    transport,
    workingtree,
    uncommit,
    )
from ....tests import (
    features,
    per_branch,
    per_transport,
    )
from .. import (
    cmds,
    )


def get_transport_scenarios():
    result = []
    basis = per_transport.transport_test_permutations()
    # Keep only the interesting ones for upload
    usable_classes = set()
    if features.paramiko.available():
        from ....transport import sftp
        usable_classes.add(sftp.SFTPTransport)
    from ....transport import local
    usable_classes.add(local.LocalTransport)
    for name, d in basis:
        t_class = d['transport_class']
        if t_class in usable_classes:
            result.append((name, d))
    return result


def load_tests(loader, standard_tests, pattern):
    """Multiply tests for tranport implementations."""
    result = loader.suiteClass()

    # one for each transport implementation
    t_tests, remaining_tests = tests.split_suite_by_condition(
        standard_tests, tests.condition_isinstance((
            TestFullUpload,
            TestIncrementalUpload,
            TestUploadFromRemoteBranch,
            )))
    tests.multiply_tests(t_tests, get_transport_scenarios(), result)

    # one for each branch format
    b_tests, remaining_tests = tests.split_suite_by_condition(
        remaining_tests, tests.condition_isinstance((
            TestBranchUploadLocations,
            )))
    tests.multiply_tests(b_tests, per_branch.branch_scenarios(),
                         result)

    # No parametrization for the remaining tests
    result.addTests(remaining_tests)

    return result


class UploadUtilsMixin:
    """Helper class to write upload tests.

    This class provides helpers to simplify test writing. The emphasis is on
    easy test writing, so each tree modification is committed. This doesn't
    preclude writing tests spawning several revisions to upload more complex
    changes.
    """

    upload_dir = 'upload'
    branch_dir = 'branch'

    def make_branch_and_working_tree(self):
        t = transport.get_transport(self.branch_dir)
        t.ensure_base()
        branch = controldir.ControlDir.create_branch_convenience(
            t.base,
            format=controldir.format_registry.make_controldir('default'),
            force_new_tree=False)
        self.tree = branch.controldir.create_workingtree()
        self.tree.commit('initial empty tree')

    def assertUpFileEqual(self, content, path, base=upload_dir):
        self.assertFileEqual(content, osutils.pathjoin(base, path))

    def assertUpPathModeEqual(self, path, expected_mode, base=upload_dir):
        # FIXME: the tests needing that assertion should depend on the server
        # ability to handle chmod so that they don't fail (or be skipped)
        # against servers that can't. Note that some breezy transports define
        # _can_roundtrip_unix_modebits in a incomplete way, this property
        # should depend on both the client and the server, not the client only.
        # But the client will know or can find if the server support chmod so
        # that's the client that will report i