From c75f9a8548b7856ac5daf15c6277552d6d4e916f Mon Sep 17 00:00:00 2001 From: Daniel Schep Date: Mon, 5 Jun 2017 18:38:42 -0400 Subject: [PATCH] fixes for ruamel.yaml 0.15 changes --- ntfy/config.py | 8 +++++++- tests/test_config.py | 4 ++-- tests/test_integration.py | 20 ++++++++++---------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/ntfy/config.py b/ntfy/config.py index fc9c707..7f4b5ac 100644 --- a/ntfy/config.py +++ b/ntfy/config.py @@ -8,6 +8,12 @@ import requests from appdirs import site_config_dir, user_config_dir +if yaml.version_info < (0, 15): + safe_load = yaml.safe_load +else: + yml = yaml.YAML(typ='safe', pure=True) + safe_load = lambda stream: yml.load(stream) + from . import __version__ DEFAULT_CONFIG = join_path(user_config_dir('ntfy', 'dschep'), 'ntfy.yml') @@ -23,7 +29,7 @@ def load_config(config_path=DEFAULT_CONFIG): logger = logging.getLogger(__name__) try: - config = yaml.safe_load(open(expanduser(config_path))) + config = safe_load(open(expanduser(config_path))) except IOError as e: if e.errno == errno.ENOENT and config_path == DEFAULT_CONFIG: logger.info('{} not found'.format(config_path)) diff --git a/tests/test_config.py b/tests/test_config.py index a023cf7..a10319f 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -25,7 +25,7 @@ def test_default_config(self): self.assertEqual(config, {}) @patch(builtin_module + '.open', mock_open()) - @patch('ntfy.config.yaml.safe_load') + @patch('ntfy.config.safe_load') def test_backwards_compat(self, mock_yamlload): mock_yamlload.return_value = {'backend': 'foobar'} config = load_config(DEFAULT_CONFIG) @@ -36,7 +36,7 @@ def test_backwards_compat(self, mock_yamlload): environ.get('CI') and py_ in [(3, 3), (3, 4)], 'Python 3.3 and 3.4 fail in TravisCI, but 3.4 works on Ubuntu 14.04') @patch(builtin_module + '.open', mock_open()) - @patch('ntfy.config.yaml.safe_load') + @patch('ntfy.config.safe_load') def test_parse_error(self, mock_yamlload): mock_yamlload.side_effect = ValueError self.assertRaises(SystemExit, load_config) diff --git a/tests/test_integration.py b/tests/test_integration.py index 05d4b51..6c393df 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -12,7 +12,7 @@ class TestIntegration(TestCase): @patch(builtin_module + '.open', mock_open()) - @patch('ntfy.config.yaml.safe_load') + @patch('ntfy.config.safe_load') @patch('ntfy.backends.pushover.requests.post') def test_pushover(self, mock_post, mock_yamlload): mock_yamlload.return_value = { @@ -22,7 +22,7 @@ def test_pushover(self, mock_post, mock_yamlload): self.assertEqual(0, ntfy_main(['send', 'foobar'])) @patch(builtin_module + '.open', mock_open()) - @patch('ntfy.config.yaml.safe_load') + @patch('ntfy.config.safe_load') @patch('ntfy.backends.prowl.requests.post') def test_prowl(self, mock_post, mock_yamlload): mock_yamlload.return_value = { @@ -32,7 +32,7 @@ def test_prowl(self, mock_post, mock_yamlload): ntfy_main(['send', 'foobar']) @patch(builtin_module + '.open', mock_open()) - @patch('ntfy.config.yaml.safe_load') + @patch('ntfy.config.safe_load') @patch('ntfy.backends.pushbullet.requests.post') def test_pushbullet(self, mock_post, mock_yamlload): mock_yamlload.return_value = { @@ -42,7 +42,7 @@ def test_pushbullet(self, mock_post, mock_yamlload): self.assertEqual(0, ntfy_main(['send', 'foobar'])) @patch(builtin_module + '.open', mock_open()) - @patch('ntfy.config.yaml.safe_load') + @patch('ntfy.config.safe_load') @patch('ntfy.backends.simplepush.requests.post') def test_simplepush(self, mock_post, mock_yamlload): mock_yamlload.return_value = { @@ -53,7 +53,7 @@ def test_simplepush(self, mock_post, mock_yamlload): @patch(builtin_module + '.open', mock_open()) @patch('ntfy.backends.default.platform', 'linux') - @patch('ntfy.config.yaml.safe_load') + @patch('ntfy.config.safe_load') def test_default(self, mock_yamlload): old_dbus = modules.get('dbus') modules['dbus'] = MagicMock() @@ -65,7 +65,7 @@ def test_default(self, mock_yamlload): modules['dbus'] = old_dbus @patch(builtin_module + '.open', mock_open()) - @patch('ntfy.config.yaml.safe_load') + @patch('ntfy.config.safe_load') def test_linux(self, mock_yamlload): old_dbus = modules.get('dbus') modules['dbus'] = MagicMock() @@ -77,7 +77,7 @@ def test_linux(self, mock_yamlload): modules['dbus'] = old_dbus @patch(builtin_module + '.open', mock_open()) - @patch('ntfy.config.yaml.safe_load') + @patch('ntfy.config.safe_load') def test_darwin(self, mock_yamlload): old_foundation = modules.get('Foundation') old_objc = modules.get('objc') @@ -97,7 +97,7 @@ def test_darwin(self, mock_yamlload): modules['AppKit'] = old_appkit @patch(builtin_module + '.open', mock_open()) - @patch('ntfy.config.yaml.safe_load') + @patch('ntfy.config.safe_load') def test_win32(self, mock_yamlload): old_win32api = modules.get('win32api') old_win32gui = modules.get('win32gui') @@ -117,7 +117,7 @@ def test_win32(self, mock_yamlload): modules['win32con'] = old_win32con @patch(builtin_module + '.open', mock_open()) - @patch('ntfy.config.yaml.safe_load') + @patch('ntfy.config.safe_load') @patch('ntfy.backends.xmpp.NtfySendMsgBot') def test_xmpp(self, mock_bot, mock_yamlload): mock_yamlload.return_value = {'backends': ['xmpp'], @@ -127,7 +127,7 @@ def test_xmpp(self, mock_bot, mock_yamlload): self.assertEqual(0, ntfy_main(['send', 'foobar'])) @patch(builtin_module + '.open', mock_open()) - @patch('ntfy.config.yaml.safe_load') + @patch('ntfy.config.safe_load') def test_instapush(self, mock_yamlload): modules['instapush'] = MagicMock() modules['instapush'].App().notify.return_value = { 'status': 200 }