fix all __builtin__.open patch/mock calls
This commit is contained in:
2 files changed
+10
-8
No files matched your search
@@ -2,6 +2,7 @@
|
||||
import unittest
|
||||
import ddt
|
||||
import mock
|
||||
from builtins import open # lets py2 use 'builtins.open' instead of '__builtin__.open' in mocking
|
||||
|
||||
OCTOPI_VERSION = "0.14.0"
|
||||
|
||||
@@ -14,7 +15,7 @@ class PiSupportTestCase(unittest.TestCase):
|
||||
def test_get_octopi_version(self):
|
||||
from octoprint.plugins.pi_support import get_octopi_version
|
||||
|
||||
with mock.patch("__builtin__.open", mock.mock_open(), create=True) as m:
|
||||
with mock.patch("builtins.open", mock.mock_open(), create=True) as m:
|
||||
m.return_value.readline.return_value = OCTOPI_VERSION
|
||||
version = get_octopi_version()
|
||||
|
||||
@@ -24,7 +25,7 @@ class PiSupportTestCase(unittest.TestCase):
|
||||
def test_get_proc_dt_model(self):
|
||||
from octoprint.plugins.pi_support import get_proc_dt_model
|
||||
|
||||
with mock.patch("__builtin__.open", mock.mock_open(), create=True) as m:
|
||||
with mock.patch("builtins.open", mock.mock_open(), create=True) as m:
|
||||
m.return_value.readline.return_value = DT_MODEL
|
||||
model = get_proc_dt_model()
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# coding=utf-8
|
||||
from __future__ import absolute_import, division, print_function
|
||||
from builtins import open # lets py2 use 'builtins.open' instead of '__builtin__.open' in mocking
|
||||
|
||||
import unittest
|
||||
import mock
|
||||
@@ -102,7 +103,7 @@ class DaemonTest(unittest.TestCase):
|
||||
@mock.patch("sys.stdout")
|
||||
@mock.patch("sys.stderr")
|
||||
@mock.patch("os.devnull")
|
||||
@mock.patch("__builtin__.open")
|
||||
@mock.patch("builtins.open")
|
||||
@mock.patch("os.dup2")
|
||||
def test_redirect_io(self, mock_dup2, mock_open, mock_devnull, mock_stderr, mock_stdout, mock_stdin):
|
||||
# setup
|
||||
@@ -390,7 +391,7 @@ class DaemonTest(unittest.TestCase):
|
||||
pid = 1234
|
||||
|
||||
# test
|
||||
with mock.patch("__builtin__.open", mock.mock_open(read_data="{}\n".format(pid)), create=True) as m:
|
||||
with mock.patch("builtins.open", mock.mock_open(read_data="{}\n".format(pid)), create=True) as m:
|
||||
result = self.daemon.get_pid()
|
||||
|
||||
# assert
|
||||
@@ -403,7 +404,7 @@ class DaemonTest(unittest.TestCase):
|
||||
handle.__enter__.side_effect = IOError()
|
||||
|
||||
# test
|
||||
with mock.patch("__builtin__.open", mock.mock_open(), create=True) as m:
|
||||
with mock.patch("builtins.open", mock.mock_open(), create=True) as m:
|
||||
result = self.daemon.get_pid()
|
||||
|
||||
# assert
|
||||
@@ -415,7 +416,7 @@ class DaemonTest(unittest.TestCase):
|
||||
pid = "not an integer"
|
||||
|
||||
# test
|
||||
with mock.patch("__builtin__.open", mock.mock_open(read_data="{}\n".format(pid)), create=True) as m:
|
||||
with mock.patch("builtins.open", mock.mock_open(read_data="{}\n".format(pid)), create=True) as m:
|
||||
result = self.daemon.get_pid()
|
||||
|
||||
# assert
|
||||
@@ -427,7 +428,7 @@ class DaemonTest(unittest.TestCase):
|
||||
pid = "1234"
|
||||
|
||||
# test
|
||||
with mock.patch("__builtin__.open", mock.mock_open(), create=True) as m:
|
||||
with mock.patch("builtins.open", mock.mock_open(), create=True) as m:
|
||||
self.daemon.set_pid(pid)
|
||||
|
||||
# assert
|
||||
@@ -440,7 +441,7 @@ class DaemonTest(unittest.TestCase):
|
||||
pid = 1234
|
||||
|
||||
# test
|
||||
with mock.patch("__builtin__.open", mock.mock_open(), create=True) as m:
|
||||
with mock.patch("builtins.open", mock.mock_open(), create=True) as m:
|
||||
self.daemon.set_pid(pid)
|
||||
|
||||
# assert
|
||||
|
||||
Reference in new issue
Block a user