GitHub

@@ -94,6 +94,11 @@ def mock_libcalamares(mocker, globalstorage):

9494

return mock_libcalamares

9595969697+

@pytest.fixture

98+

def mock_open_ngcconf(mocker):

99+

return mocker.Mock('open("nixos-generate-config.conf")')

100+101+97102

@pytest.fixture

98103

def mock_open_hwconf(mocker):

99104

return mocker.Mock('open("hardware-configuration.nix")')

@@ -105,9 +110,13 @@ def mock_open_kbdmodelmap(mocker):

105110106111107112

@pytest.fixture

108-

def mock_open(mocker, mock_open_hwconf, mock_open_kbdmodelmap):

113+

def mock_open(mocker, mock_open_ngcconf, mock_open_hwconf, mock_open_kbdmodelmap):

109114

testing_dir = os.path.dirname(__file__)

110115116+

ngcconf_txt = ""

117+

with open(os.path.join(testing_dir, "nixos-generate-config.conf"), "r") as ngcconf:

118+

ngcconf_txt = ngcconf.read()

119+111120

hwconf_txt = ""

112121

with open(os.path.join(testing_dir, "hardware-configuration.nix"), "r") as hwconf:

113122

hwconf_txt = hwconf.read()

@@ -118,12 +127,13 @@ def mock_open(mocker, mock_open_hwconf, mock_open_kbdmodelmap):

118127119128

mock_open = mocker.Mock("open")

120129121-

def fake_open(*args):

122-

file, mode, *_ = args

123-124-

assert mode == "r", "open() called without the 'r' mode"

130+

def fake_open(*args, **kwargs):

131+

file, *mode = args

132+

assert len(mode) == 0 or mode[0] == "r", "open() called with non-'r' mode"

125133126-

if file.endswith("hardware-configuration.nix"):

134+

if file.endswith("nixos-generate-config.conf"):

135+

return mocker.mock_open(mock=mock_open_ngcconf, read_data=ngcconf_txt)(*args)

136+

elif file.endswith("hardware-configuration.nix"):

127137

return mocker.mock_open(mock=mock_open_hwconf, read_data=hwconf_txt)(*args)

128138

elif file.endswith("kbd-model-map"):

129139

return mocker.mock_open(

Read the original on github.com ↗