1
# Copyright (C) 2016 Canonical Ltd.
3
# Author: Scott Moser <scott.moser@canonical.com>
5
# Curtin is free software: you can redistribute it and/or modify it under
6
# the terms of the GNU Affero General Public License as published by the
7
# Free Software Foundation, either version 3 of the License, or (at your
8
# option) any later version.
10
# Curtin is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
15
# You should have received a copy of the GNU Affero General Public License
16
# along with Curtin. If not, see <http://www.gnu.org/licenses/>.
20
class mocked_open(object):
21
# older versions of mock can't really mock the builtin 'open' easily.
27
return self.mocked.start()
29
py2_p = '__builtin__.open'
30
py3_p = 'builtins.open'
32
self.mocked = mock.patch(py2_p, new_callable=mock.mock_open())
33
return self.mocked.start()
35
self.mocked = mock.patch(py3_p, new_callable=mock.mock_open())
36
return self.mocked.start()
38
def __exit__(self, etype, value, trace):