~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/__init__.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2007-09-05 08:48:24 UTC
  • mfrom: (2785.1.7 show-version)
  • Revision ID: pqm@pqm.ubuntu.com-20070905084824-xdwd8f4fioovdi9v
bugfix #131100: bzr --version should care about encoding of stdout
 (bialix,r=ianc)

Show diffs side-by-side

added added

removed removed

Lines of Context:
2652
2652
        new_id = "%s(%s)" % (new_test.id(), scenario[0])
2653
2653
        new_test.id = lambda: new_id
2654
2654
        return new_test
 
2655
 
 
2656
 
 
2657
def probe_unicode_in_user_encoding():
 
2658
    """Try to encode several unicode strings to use in unicode-aware tests.
 
2659
    Return first successfull match.
 
2660
 
 
2661
    :return:  (unicode value, encoded plain string value) or (None, None)
 
2662
    """
 
2663
    possible_vals = [u'm\xb5', u'\xe1', u'\u0410']
 
2664
    for uni_val in possible_vals:
 
2665
        try:
 
2666
            str_val = uni_val.encode(bzrlib.user_encoding)
 
2667
        except UnicodeEncodeError:
 
2668
            # Try a different character
 
2669
            pass
 
2670
        else:
 
2671
            return uni_val, str_val
 
2672
    return None, None