[merge] follow up, fix the rest of the mac tests
John Arbash Meinel
john at arbash-meinel.com
Tue Jul 4 21:03:53 BST 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Martin Pool wrote:
> On 3 Jul 2006, John Arbash Meinel <john at arbash-meinel.com> wrote:
>> I went ahead and fixed up the rest of the mac tests. It turned out the
>> only thing left was to write a new getcwd() for Mac, which returns the
>> normalized path. And then track down WorkingTree, since it was directly
>> calling os.getcwdu() instead of osutils.getcwd().
>>
>> Anyway, combining the previous patch with this patch means all tests
>> pass on Mac.
>
> +1, great work.
>
>> +def _mac_getcwd():
>> + return unicodedata.normalize('NFKC', os.getcwdu())
>> +
>> +
>
> It might have been covered by your previous patch, but it seems to me
> there ought to be a comment or docstring (or HACKING entry) saying
> when/why you should call osutils.getcwd rather than os.getcwd().
I added this to HACKING:
OS Abstractions
===============
There are several functions in osutils.py which provide an abstraction
layer above the python builtin ``os`` functions. In general, the ``os``
module is designed as a way to abstract performing a given operation,
but doing so in native paths. Because bzr records paths, it needs a way
to change natives paths to be consistent across platforms. Specifically,
on win32, we need to change backwards slashes to forward slashes, and on
Mac OSX we need to change the unicode normalization of files. Because of
this, it is generally better to call the ``osutils`` function instead of
the ``os`` function. Care is taken such that the returned paths can
still be accessed by standard functions, but the paths themselves will
be more consistent across platforms.
Is that a reasonable statement?
>
>> +class TestMacFuncsDirs(TestCaseInTempDir):
>> + """Test mac special functions that require directories."""
>> +
>> + def test_getcwd(self):
>> + # On Mac, this will actually create Ba\u030agfors
>> + # but chdir will still work, because it accepts both paths
>> + try:
>> + os.mkdir(u'B\xe5gfors')
>> + except UnicodeError:
>> + raise TestSkipped("Unable to create Unicode filename")
>> +
>> + os.chdir(u'B\xe5gfors')
>> + self.assertEndsWith(osutils._mac_getcwd(), u'B\xe5gfors')
>> +
>> + def test_getcwd_nonnorm(self):
>> + # Test that _mac_getcwd() will normalize this path
>> + try:
>> + os.mkdir(u'Ba\u030agfors')
>> + except UnicodeError:
>> + raise TestSkipped("Unable to create Unicode filename")
>> +
>> + os.chdir(u'Ba\u030agfors')
>> + self.assertEndsWith(osutils._mac_getcwd(), u'B\xe5gfors')
>> +
>
> These two could perhaps do with a comment explaining why calling the
> _mac_getcwd function is safe on other platforms. (I think it is, and
> it's nice that we can test it everywhere.)
>
It is safe, because we aren't trying to access the path returned. (Linux
and windows would not be able to access u'B\xe5gfors' in the second
test). But the function itself is perfectly safe to call.
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFEqsmpJdeBCYSNAAMRAs2cAKCsjTUJAfaX/TIIi0uybqBESX8nDgCglw6/
W/+hjYSkQfjNrx8MkDdv0SQ=
=5oMO
-----END PGP SIGNATURE-----
More information about the bazaar
mailing list