From 595ffec2bb55f80c8d7d1b5742b2ac4bad58ea92 Mon Sep 17 00:00:00 2001 From: Thomas Gambier <thomas.gambier@nexedi.com> Date: Fri, 2 Aug 2019 20:16:24 +0200 Subject: [PATCH] [slapos.cookbook] fix failures in slapos.test.test_recipe.additional_tests --- slapos/test/recipe/test_pbs.py | 4 ++-- slapos/test/recipe/test_plugin.py | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/slapos/test/recipe/test_pbs.py b/slapos/test/recipe/test_pbs.py index 08327f827..2b7397978 100644 --- a/slapos/test/recipe/test_pbs.py +++ b/slapos/test/recipe/test_pbs.py @@ -27,7 +27,7 @@ class PBSTest(unittest.TestCase): local_dir='TEST_LOCAL_DIR', remote_dir='TEST_REMOTE_DIR', rdiff_wrapper_path=rdiff_wrapper.name) - content = rdiff_wrapper.read() + content = open(rdiff_wrapper.name, 'r').read() self.assertIn('--remote-schema TEST_REMOTE_SCHEMA', content) self.assertIn('TEST_LOCAL_DIR', content) self.assertIn('TEST_REMOTE_DIR', content) @@ -41,7 +41,7 @@ class PBSTest(unittest.TestCase): remote_dir='TEST_REMOTE_DIR', rdiff_wrapper_path=rdiff_wrapper.name, remove_backup_older_than='TEST_OLDER') - content = rdiff_wrapper.read() + content = open(rdiff_wrapper.name, 'r').read() self.assertIn('--remote-schema TEST_REMOTE_SCHEMA', content) self.assertIn('TEST_LOCAL_DIR', content) self.assertIn('TEST_REMOTE_DIR', content) diff --git a/slapos/test/recipe/test_plugin.py b/slapos/test/recipe/test_plugin.py index 5576bf12b..730dd960c 100644 --- a/slapos/test/recipe/test_plugin.py +++ b/slapos/test/recipe/test_plugin.py @@ -1,6 +1,7 @@ import os, shutil, tempfile, unittest from slapos.recipe import promise_plugin from slapos.test.utils import makeRecipe +from pprint import pformat import stat, json class TestPromisePlugin(unittest.TestCase): @@ -33,7 +34,7 @@ in multi line recipe.install() self.assertTrue(os.path.exists(self.output)) - with open(self.output) as f: + with open(self.output, 'r') as f: content = f.read() self.assertIn("from slapos.promise.plugin.check_site_available import RunPromise", content) self.assertEqual(stat.S_IMODE(os.stat(self.output).st_mode), int('644', 8)) @@ -44,7 +45,7 @@ in multi line param3=self.options['config-param3'], param4=self.options['config-param4'], ) - self.assertIn('extra_config_dict = json.loads("""%s""", strict=False)' % json.dumps(expected_dict, indent=2, sort_keys=True), content) + self.assertIn('extra_config_dict = %s' % pformat(expected_dict, indent=2), content) def test_no_module_set(self): recipe = makeRecipe( @@ -67,7 +68,7 @@ in multi line with open(self.output) as f: content = f.read() self.assertIn("from slapos.promise.plugin.check_site_available import RunPromise", content) - self.assertIn('extra_config_dict = json.loads("""{}""", strict=False)', content) + self.assertIn('extra_config_dict = { }', content) def test_bad_parameters(self): @@ -84,8 +85,8 @@ in multi line with open(self.output) as f: content = f.read() - expected_param1 = '"param1; print \\"toto\\"": "#xxxx\\"\\nimport os; os.stat(f)",' - expected_param2 = '"param2\\n@domething": "\\"#$$*PPP\\n\\n p = 2*5; print \\"result is %s\\" % p"' + expected_param1 = r"""'param1; print "toto"': '#xxxx"\nimport os; os.stat(f)',""" + expected_param2 = r"""'param2\n@domething': '"#$$*PPP\n\n p = 2*5; print "result is %s" % p'""" self.assertIn(expected_param1, content) self.assertIn(expected_param2, content) -- 2.30.9