From 803e00f6b1ad3cb92096b006a6f8f15a10bd5b2d Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 7 Apr 2021 09:26:28 -0400 Subject: [PATCH] Tests pass on Python 3. --- src/allmydata/test/test_multi_introducers.py | 27 +++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/allmydata/test/test_multi_introducers.py b/src/allmydata/test/test_multi_introducers.py index bb22d551f..a016d4977 100644 --- a/src/allmydata/test/test_multi_introducers.py +++ b/src/allmydata/test/test_multi_introducers.py @@ -1,6 +1,9 @@ -#!/usr/bin/python +from past.builtins import unicode + import os +from six import ensure_binary + from twisted.python.filepath import FilePath from twisted.trial import unittest from twisted.internet import defer @@ -43,7 +46,7 @@ class MultiIntroTests(unittest.TestCase): u'intro2':{ 'furl': 'furl4' }, }, } - self.yaml_path.setContent(yamlutil.safe_dump(connections)) + self.yaml_path.setContent(ensure_binary(yamlutil.safe_dump(connections))) # get a client and count of introducer_clients myclient = yield create_client(self.basedir) ic_count = len(myclient.introducer_clients) @@ -73,7 +76,7 @@ class MultiIntroTests(unittest.TestCase): tahoe_cfg_furl = myclient.introducer_clients[0].introducer_furl # assertions - self.failUnlessEqual(fake_furl, tahoe_cfg_furl) + self.failUnlessEqual(fake_furl, unicode(tahoe_cfg_furl, "utf-8")) self.assertEqual( list( warning["message"] @@ -97,10 +100,10 @@ class MultiIntroTests(unittest.TestCase): u'default': { 'furl': 'furl1' }, }, } - self.yaml_path.setContent(yamlutil.safe_dump(connections)) + self.yaml_path.setContent(ensure_binary(yamlutil.safe_dump(connections))) FilePath(self.basedir).child("tahoe.cfg").setContent( - "[client]\n" - "introducer.furl = furl1\n" + b"[client]\n" + b"introducer.furl = furl1\n" ) with self.assertRaises(ValueError) as ctx: @@ -112,7 +115,7 @@ class MultiIntroTests(unittest.TestCase): "please fix impossible configuration.", ) -SIMPLE_YAML = """ +SIMPLE_YAML = b""" introducers: one: furl: furl1 @@ -121,7 +124,7 @@ introducers: # this format was recommended in docs/configuration.rst in 1.12.0, but it # isn't correct (the "furl = furl1" line is recorded as the string value of # the ["one"] key, instead of being parsed as a single-key dictionary). -EQUALS_YAML = """ +EQUALS_YAML = b""" introducers: one: furl = furl1 """ @@ -147,17 +150,17 @@ class NoDefault(unittest.TestCase): connections = {'introducers': { u'one': { 'furl': 'furl1' }, }} - self.yaml_path.setContent(yamlutil.safe_dump(connections)) + self.yaml_path.setContent(ensure_binary(yamlutil.safe_dump(connections))) myclient = yield create_client(self.basedir) tahoe_cfg_furl = myclient.introducer_clients[0].introducer_furl - self.assertEquals(tahoe_cfg_furl, 'furl1') + self.assertEquals(tahoe_cfg_furl, b'furl1') @defer.inlineCallbacks def test_real_yaml(self): self.yaml_path.setContent(SIMPLE_YAML) myclient = yield create_client(self.basedir) tahoe_cfg_furl = myclient.introducer_clients[0].introducer_furl - self.assertEquals(tahoe_cfg_furl, 'furl1') + self.assertEquals(tahoe_cfg_furl, b'furl1') @defer.inlineCallbacks def test_invalid_equals_yaml(self): @@ -172,6 +175,6 @@ class NoDefault(unittest.TestCase): @defer.inlineCallbacks def test_introducerless(self): connections = {'introducers': {} } - self.yaml_path.setContent(yamlutil.safe_dump(connections)) + self.yaml_path.setContent(ensure_binary(yamlutil.safe_dump(connections))) myclient = yield create_client(self.basedir) self.assertEquals(len(myclient.introducer_clients), 0)