def test_serialize_called_onflush(serializable): _dummy_str = "dummy" with mock.patch("{}.open".format(builtins), create=True) as open_mock: FileMixin(__fileinfo__, serializable.return_value).flush(_dummy_str) assert serializable.return_value._deserialize.called_with( _dummy_str, open_mock)
def test_deserialize_called_onload(serializable): with mock.patch("{}.open".format(builtins), create=True) as open_mock: FileMixin(__fileinfo__, serializable.return_value).load() assert serializable.return_value._deserialize.called_with(open_mock)
def test_json_serialize(): with mock.patch("{}.open".format(builtins), mock.mock_open()) as mockopen: JsonFile(__fileinfo__).flush(json_obj) assert mockopen.return_value.write.called_with(json_str)
def test_createfile_notcalled_ifexists(serializable, createfile): with mock.patch("app_settings.mixins.__file_exists__", return_value=True): _file = FileMixin(__fileinfo__, serializable, auto_create=True) assert not createfile.called
def test_json_deserialize_autocreate(createfile): with mock.patch("{}.open".format(builtins), mock.mock_open(read_data=json_str)): read_obj = JsonFile(__fileinfo__, auto_create=True).load() assert read_obj == json_obj