From c4dcefd657c5de59bf1d95a5dd3458c329106105 Mon Sep 17 00:00:00 2001 From: Kyr Shatskyy Date: Fri, 13 Dec 2019 13:13:14 +0100 Subject: [PATCH] test: replace __builtin__ with module path for py3 Signed-off-by: Kyr Shatskyy --- teuthology/test/test_ls.py | 11 +++++++---- teuthology/test/test_misc.py | 2 +- teuthology/test/test_report.py | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/teuthology/test/test_ls.py b/teuthology/test/test_ls.py index 6046c8619..48ff1ce4d 100644 --- a/teuthology/test/test_ls.py +++ b/teuthology/test/test_ls.py @@ -23,7 +23,7 @@ class TestLs(object): m_safe_load_all.return_value = [{"failure_reason": "reasons"}] ls.ls("some/archive/div", True) - @patch("__builtin__.open") + @patch("teuthology.ls.open") @patch("teuthology.ls.get_jobs") def test_ls_ioerror(self, m_get_jobs, m_open): m_get_jobs.return_value = ["1", "2"] @@ -31,7 +31,7 @@ class TestLs(object): with pytest.raises(IOError): ls.ls("some/archive/dir", True) - @patch("__builtin__.open") + @patch("teuthology.ls.open") @patch("os.popen") @patch("os.path.isdir") @patch("os.path.isfile") @@ -40,6 +40,9 @@ class TestLs(object): m_isdir.return_value = True m_popen.return_value = Mock() cmdline = Mock() - cmdline.find.return_value = True - m_open.return_value = cmdline + cmdline.find = Mock(return_value=0) + m1 = Mock() + m2 = Mock() + m2.read = Mock(return_value=cmdline) + m_open.side_effect = [m1, m2] ls.print_debug_info("the_job", "job/dir", "some/archive/dir") diff --git a/teuthology/test/test_misc.py b/teuthology/test/test_misc.py index b0b6b8772..bb4e67d90 100644 --- a/teuthology/test/test_misc.py +++ b/teuthology/test/test_misc.py @@ -298,7 +298,7 @@ class TestMergeConfigs(object): @patch("os.path.exists") @patch("yaml.safe_load") - @patch("__builtin__.open") + @patch("teuthology.misc.open") def test_merge_configs(self, m_open, m_safe_load, m_exists): """ Only tests with one yaml file being passed, mainly just to test the loop logic. The actual merge will be tested in subsequent diff --git a/teuthology/test/test_report.py b/teuthology/test/test_report.py index 2d13b7d97..1a33b12b4 100644 --- a/teuthology/test/test_report.py +++ b/teuthology/test/test_report.py @@ -1,6 +1,6 @@ import yaml import json -import fake_archive +from teuthology.test import fake_archive from teuthology import report -- 2.47.3