~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to doc/developers/testing.txt

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
745
745
        _test_needs_features = [features.apport]
746
746
 
747
747
 
 
748
Testing translations
 
749
-----------------------
 
750
 
 
751
Translations are disabled by default in tests.  If you want to test
 
752
that code is translated you can use the ``ZzzTranslations`` class from
 
753
``test_i18n``::
 
754
 
 
755
    self.overrideAttr(i18n, '_translations', ZzzTranslations())
 
756
 
 
757
And check the output strings look like ``u"zz\xe5{{output}}"``.
 
758
 
 
759
To test the gettext setup and usage you override i18n.installed back
 
760
to self.i18nInstalled and _translations to None, see
 
761
test_i18n.TestInstall.
 
762
 
 
763
 
748
764
Testing deprecated code
749
765
-----------------------
750
766
 
1018
1034
 
1019
1035
    self.overrideAttr(osutils, '_cached_user_encoding', 'latin-1')
1020
1036
 
 
1037
This should be used with discretion; sometimes it's better to make the
 
1038
underlying code more testable so that you don't need to rely on monkey
 
1039
patching.
 
1040
 
 
1041
 
 
1042
Observing calls to a function
 
1043
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
1044
 
 
1045
Sometimes it's useful to observe how a function is called, typically when
 
1046
calling it has side effects but the side effects are not easy to observe
 
1047
from a test case.  For instance the function may be expensive and we want
 
1048
to assert it is not called too many times, or it has effects on the
 
1049
machine that are safe to run during a test but not easy to measure.  In
 
1050
these cases, you can use `recordCalls` which will monkey-patch in a
 
1051
wrapper that records when the function is called.
 
1052
 
 
1053
 
1021
1054
Temporarily changing environment variables
1022
1055
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1023
1056
 
1072
1105
 
1073
1106
    tc qdisc add dev lo root handle 1: prio
1074
1107
    tc qdisc add dev lo parent 1:3 handle 30: netem delay 500ms 
1075
 
    tc qdisc add dev lo parent 30:1 handle 40: prio
1076
 
    tc filter add dev lo protocol ip parent 1:0 prio 3 u32 match ip dport 4155 0xffff flowid 1:3 handle 800::800
1077
 
    tc filter add dev lo protocol ip parent 1:0 prio 3 u32 match ip sport 4155 0xffff flowid 1:3 handle 800::801
 
1108
    tc filter add dev lo protocol ip parent 1:0 prio 3 u32 match ip dport 4155 0xffff flowid 1:3 
 
1109
    tc filter add dev lo protocol ip parent 1:0 prio 3 u32 match ip sport 4155 0xffff flowid 1:3 
1078
1110
 
1079
1111
and to remove this::
1080
1112