diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index 3884965c5..1bcafbe3d 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -112,7 +112,11 @@ namespace std::string const key = extract(iterkeys[i]); int sett = setting_by_name(key); - if (sett < 0) continue; + if (sett < 0) + { + PyErr_SetString(PyExc_ValueError, ("unknown name in settings_pack: " + key).c_str()); + throw_error_already_set(); + } TORRENT_TRY { diff --git a/bindings/python/test.py b/bindings/python/test.py index 3d6ff5325..76fce40b5 100644 --- a/bindings/python/test.py +++ b/bindings/python/test.py @@ -81,7 +81,7 @@ class test_torrent_info(unittest.TestCase): idx = 0 expected = ['bar.txt', 'var.txt'] for f in files: - print f.path + print(f.path) self.assertEqual(os.path.split(f.path)[1], expected[idx]) self.assertEqual(os.path.split(os.path.split(f.path)[0]), ('temp', 'foo')) @@ -165,6 +165,13 @@ class test_session(unittest.TestCase): self.assertTrue(isinstance(a.values, dict)) self.assertTrue(len(a.values) > 0) + def test_unknown_settings(self): + try: + s = lt.session({'unexpected-key-name': 42}) + self.assertFalse('should have thrown an exception') + except Exception as e: + print(e) + def test_deprecated_settings(self): # this detects whether libtorrent was built with deprecated APIs