Skip to content

Commit

Permalink
Merge pull request #149 from dschep/yaml-0.15
Browse files Browse the repository at this point in the history
fixes for ruamel.yaml 0.15 changes
  • Loading branch information
dschep authored Jun 5, 2017
2 parents 0659971 + c75f9a8 commit 5122ce2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
8 changes: 7 additions & 1 deletion ntfy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
20 changes: 10 additions & 10 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -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 = {
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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'],
Expand All @@ -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 }
Expand Down

0 comments on commit 5122ce2

Please sign in to comment.