view tests/test_push_eol.py @ 1101:4a92eb1484ba

layouts: fix crash when importing hgsubversion itself (issue #402) Mercurial extensions are a bit weird: they aren't normally in sys.path, so you can't assume that "import hgsubversion" works. Luckily, Mercurial sneaks a little treat into sys.modules so that "import hgext_hgsubversion" does work. In fact, to get things working *as a Mercurial extension*, all that's needed is that trivial change to two import lines, in layouts/detect.py and layouts/standard.py. Unfortunately, hgsubversion is also imported as a Python module, in its own test suite. In that context, there is no "hgext_" trick -- unless we do it in ourselves, which I've done in TestBase.setUp(). That would work fine ... except that test_util imports from hgsubversion, which ends up importing hgsubversion.layouts.{detect,standard}, which want the "hgext_" trick to work. But it hasn't been done yet when we're still importing; it doesn't happen until setUp() runs. So make those two imports happen late, in the functions that need them. Incidentally, this is only necessary to support Mercurial <= 2.7. Mercurial got a bit smarter in 2.8: http://selenic.com/repo/hg/rev/621a26eb3a99
author Greg Ward <greg@gerg.ca>
date Thu, 02 Jan 2014 21:53:39 -0500
parents 23992b41b6b7
children
line wrap: on
line source

import test_util

import unittest

class TestPushEol(test_util.TestBase):
    obsolete_mode_tests = True
    stupid_mode_tests = True

    def setUp(self):
        test_util.TestBase.setUp(self)
        self._load_fixture_and_fetch('emptyrepo.svndump')

    def test_push_dirs(self):
        changes = [
            # Root files with LF, CRLF and mixed EOL
            ('lf', 'lf', 'a\nb\n\nc'),
            ('crlf', 'crlf', 'a\r\nb\r\n\r\nc'),
            ('mixed', 'mixed', 'a\r\nb\n\r\nc\nd'),
            ]
        self.commitchanges(changes)
        self.pushrevisions()
        self.assertchanges(changes, self.repo['tip'])

        changes = [
            # Update all files once, with same EOL
            ('lf', 'lf', 'a\nb\n\nc\na\nb\n\nc'),
            ('crlf', 'crlf', 'a\r\nb\r\n\r\nc\r\na\r\nb\r\n\r\nc'),
            ('mixed', 'mixed', 'a\r\nb\n\r\nc\nd\r\na\r\nb\n\r\nc\nd'),
            ]
        self.commitchanges(changes)
        self.pushrevisions()
        self.assertchanges(changes, self.repo['tip'])