X-Git-Url: http://git.cascardo.eti.br/?a=blobdiff_plain;f=tests%2Ftest-json.py;h=6750481e8af3172937402d5a71d6cddcc2a96579;hb=64eb96a9af0917a4c7b8e0441d2e49404fd247d5;hp=13561458e41df02596d8a9d8fed42c1534f10ec5;hpb=f3068bff92dc4fb76ee4aab149990f2492bcbc24;p=cascardo%2Fovs.git diff --git a/tests/test-json.py b/tests/test-json.py index 13561458e..6750481e8 100644 --- a/tests/test-json.py +++ b/tests/test-json.py @@ -12,16 +12,19 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import print_function + import codecs import getopt import sys import ovs.json +import six def print_json(json): - if type(json) in [str, unicode]: - print "error: %s" % json + if isinstance(json, six.string_types): + print("error: %s" % json) return False else: ovs.json.to_stream(json, sys.stdout) @@ -55,9 +58,11 @@ def parse_multiple(stream): def main(argv): argv0 = argv[0] - # Make stdout and stderr UTF-8, even if they are redirected to a file. - sys.stdout = codecs.getwriter("utf-8")(sys.stdout) - sys.stderr = codecs.getwriter("utf-8")(sys.stderr) + # When this is used with Python 3, the program produces no output. + if sys.version_info[0] == 2: + # Make stdout and stderr UTF-8, even if they are redirected to a file. + sys.stdout = codecs.getwriter("utf-8")(sys.stdout) + sys.stderr = codecs.getwriter("utf-8")(sys.stderr) try: options, args = getopt.gnu_getopt(argv[1:], '', ['multiple'])