Skip to content

Commit 5122ce2

Browse files
authored
Merge pull request #149 from dschep/yaml-0.15
fixes for ruamel.yaml 0.15 changes
2 parents 0659971 + c75f9a8 commit 5122ce2

3 files changed

Lines changed: 19 additions & 13 deletions

File tree

ntfy/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
import requests
99
from appdirs import site_config_dir, user_config_dir
1010

11+
if yaml.version_info < (0, 15):
12+
safe_load = yaml.safe_load
13+
else:
14+
yml = yaml.YAML(typ='safe', pure=True)
15+
safe_load = lambda stream: yml.load(stream)
16+
1117
from . import __version__
1218

1319
DEFAULT_CONFIG = join_path(user_config_dir('ntfy', 'dschep'), 'ntfy.yml')
@@ -23,7 +29,7 @@ def load_config(config_path=DEFAULT_CONFIG):
2329
logger = logging.getLogger(__name__)
2430

2531
try:
26-
config = yaml.safe_load(open(expanduser(config_path)))
32+
config = safe_load(open(expanduser(config_path)))
2733
except IOError as e:
2834
if e.errno == errno.ENOENT and config_path == DEFAULT_CONFIG:
2935
logger.info('{} not found'.format(config_path))

tests/test_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_default_config(self):
2525
self.assertEqual(config, {})
2626

2727
@patch(builtin_module + '.open', mock_open())
28-
@patch('ntfy.config.yaml.safe_load')
28+
@patch('ntfy.config.safe_load')
2929
def test_backwards_compat(self, mock_yamlload):
3030
mock_yamlload.return_value = {'backend': 'foobar'}
3131
config = load_config(DEFAULT_CONFIG)
@@ -36,7 +36,7 @@ def test_backwards_compat(self, mock_yamlload):
3636
environ.get('CI') and py_ in [(3, 3), (3, 4)],
3737
'Python 3.3 and 3.4 fail in TravisCI, but 3.4 works on Ubuntu 14.04')
3838
@patch(builtin_module + '.open', mock_open())
39-
@patch('ntfy.config.yaml.safe_load')
39+
@patch('ntfy.config.safe_load')
4040
def test_parse_error(self, mock_yamlload):
4141
mock_yamlload.side_effect = ValueError
4242
self.assertRaises(SystemExit, load_config)

tests/test_integration.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class TestIntegration(TestCase):
1414
@patch(builtin_module + '.open', mock_open())
15-
@patch('ntfy.config.yaml.safe_load')
15+
@patch('ntfy.config.safe_load')
1616
@patch('ntfy.backends.pushover.requests.post')
1717
def test_pushover(self, mock_post, mock_yamlload):
1818
mock_yamlload.return_value = {
@@ -22,7 +22,7 @@ def test_pushover(self, mock_post, mock_yamlload):
2222
self.assertEqual(0, ntfy_main(['send', 'foobar']))
2323

2424
@patch(builtin_module + '.open', mock_open())
25-
@patch('ntfy.config.yaml.safe_load')
25+
@patch('ntfy.config.safe_load')
2626
@patch('ntfy.backends.prowl.requests.post')
2727
def test_prowl(self, mock_post, mock_yamlload):
2828
mock_yamlload.return_value = {
@@ -32,7 +32,7 @@ def test_prowl(self, mock_post, mock_yamlload):
3232
ntfy_main(['send', 'foobar'])
3333

3434
@patch(builtin_module + '.open', mock_open())
35-
@patch('ntfy.config.yaml.safe_load')
35+
@patch('ntfy.config.safe_load')
3636
@patch('ntfy.backends.pushbullet.requests.post')
3737
def test_pushbullet(self, mock_post, mock_yamlload):
3838
mock_yamlload.return_value = {
@@ -42,7 +42,7 @@ def test_pushbullet(self, mock_post, mock_yamlload):
4242
self.assertEqual(0, ntfy_main(['send', 'foobar']))
4343

4444
@patch(builtin_module + '.open', mock_open())
45-
@patch('ntfy.config.yaml.safe_load')
45+
@patch('ntfy.config.safe_load')
4646
@patch('ntfy.backends.simplepush.requests.post')
4747
def test_simplepush(self, mock_post, mock_yamlload):
4848
mock_yamlload.return_value = {
@@ -53,7 +53,7 @@ def test_simplepush(self, mock_post, mock_yamlload):
5353

5454
@patch(builtin_module + '.open', mock_open())
5555
@patch('ntfy.backends.default.platform', 'linux')
56-
@patch('ntfy.config.yaml.safe_load')
56+
@patch('ntfy.config.safe_load')
5757
def test_default(self, mock_yamlload):
5858
old_dbus = modules.get('dbus')
5959
modules['dbus'] = MagicMock()
@@ -65,7 +65,7 @@ def test_default(self, mock_yamlload):
6565
modules['dbus'] = old_dbus
6666

6767
@patch(builtin_module + '.open', mock_open())
68-
@patch('ntfy.config.yaml.safe_load')
68+
@patch('ntfy.config.safe_load')
6969
def test_linux(self, mock_yamlload):
7070
old_dbus = modules.get('dbus')
7171
modules['dbus'] = MagicMock()
@@ -77,7 +77,7 @@ def test_linux(self, mock_yamlload):
7777
modules['dbus'] = old_dbus
7878

7979
@patch(builtin_module + '.open', mock_open())
80-
@patch('ntfy.config.yaml.safe_load')
80+
@patch('ntfy.config.safe_load')
8181
def test_darwin(self, mock_yamlload):
8282
old_foundation = modules.get('Foundation')
8383
old_objc = modules.get('objc')
@@ -97,7 +97,7 @@ def test_darwin(self, mock_yamlload):
9797
modules['AppKit'] = old_appkit
9898

9999
@patch(builtin_module + '.open', mock_open())
100-
@patch('ntfy.config.yaml.safe_load')
100+
@patch('ntfy.config.safe_load')
101101
def test_win32(self, mock_yamlload):
102102
old_win32api = modules.get('win32api')
103103
old_win32gui = modules.get('win32gui')
@@ -117,7 +117,7 @@ def test_win32(self, mock_yamlload):
117117
modules['win32con'] = old_win32con
118118

119119
@patch(builtin_module + '.open', mock_open())
120-
@patch('ntfy.config.yaml.safe_load')
120+
@patch('ntfy.config.safe_load')
121121
@patch('ntfy.backends.xmpp.NtfySendMsgBot')
122122
def test_xmpp(self, mock_bot, mock_yamlload):
123123
mock_yamlload.return_value = {'backends': ['xmpp'],
@@ -127,7 +127,7 @@ def test_xmpp(self, mock_bot, mock_yamlload):
127127
self.assertEqual(0, ntfy_main(['send', 'foobar']))
128128

129129
@patch(builtin_module + '.open', mock_open())
130-
@patch('ntfy.config.yaml.safe_load')
130+
@patch('ntfy.config.safe_load')
131131
def test_instapush(self, mock_yamlload):
132132
modules['instapush'] = MagicMock()
133133
modules['instapush'].App().notify.return_value = { 'status': 200 }

0 commit comments

Comments
 (0)