From f44fb4c66005af93f8598b0be2f88f5f4bcc0bd0 Mon Sep 17 00:00:00 2001 From: arvidn Date: Wed, 6 Jan 2016 00:17:51 -0500 Subject: [PATCH] extend python binding unit test and fix bugs in it --- bindings/python/src/datetime.cpp | 16 ++++++++++++++++ bindings/python/src/session.cpp | 3 ++- bindings/python/src/torrent_status.cpp | 2 ++ bindings/python/test.py | 16 +++++++++++++++- 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/bindings/python/src/datetime.cpp b/bindings/python/src/datetime.cpp index da1347671..7423de9aa 100644 --- a/bindings/python/src/datetime.cpp +++ b/bindings/python/src/datetime.cpp @@ -6,8 +6,10 @@ #include #include "optional.hpp" #include +#include "libtorrent/time.hpp" using namespace boost::python; +namespace lt = libtorrent; #if BOOST_VERSION < 103400 @@ -25,6 +27,15 @@ object import(str name) object datetime_timedelta; object datetime_datetime; +struct chrono_time_duration_to_python +{ + static PyObject* convert(lt::time_duration const& d) + { + return incref(object(lt::duration_cast(d).count() + / 1000.f).ptr()); + } +}; + struct time_duration_to_python { static PyObject* convert(boost::posix_time::time_duration const& d) @@ -76,6 +87,11 @@ void bind_datetime() , ptime_to_python >(); + to_python_converter< + lt::time_duration + , chrono_time_duration_to_python + >(); + optional_to_python(); } diff --git a/bindings/python/src/session.cpp b/bindings/python/src/session.cpp index 3bf51bc38..cb24ca975 100644 --- a/bindings/python/src/session.cpp +++ b/bindings/python/src/session.cpp @@ -388,7 +388,7 @@ namespace #endif #ifndef TORRENT_NO_DEPRECATE - boost::shared_ptr + boost::shared_ptr #else alert const* #endif @@ -916,6 +916,7 @@ void bind_session() typedef void (*perf_preset2)(settings_pack& s); #ifndef TORRENT_NO_DEPRECATE + typedef session_settings (*mem_preset1)(); typedef session_settings (*perf_preset1)(); diff --git a/bindings/python/src/torrent_status.cpp b/bindings/python/src/torrent_status.cpp index d9180aecf..b6e0228a2 100644 --- a/bindings/python/src/torrent_status.cpp +++ b/bindings/python/src/torrent_status.cpp @@ -102,6 +102,8 @@ void bind_torrent_status() #endif .def_readonly("errc", &torrent_status::errc) .def_readonly("error_file", &torrent_status::error_file) + .def_readonly("name", &torrent_status::name) + .def_readonly("save_path", &torrent_status::save_path) .def_readonly("priority", &torrent_status::priority) .def_readonly("added_time", &torrent_status::added_time) .def_readonly("completed_time", &torrent_status::completed_time) diff --git a/bindings/python/test.py b/bindings/python/test.py index ecfcdd4e8..3d039717e 100644 --- a/bindings/python/test.py +++ b/bindings/python/test.py @@ -34,9 +34,23 @@ class test_alerts(unittest.TestCase): h = ses.add_torrent({'ti': ti, 'save_path': '.'}) time.sleep(1) ses.remove_torrent(h) + ses.wait_for_alert(1000) # milliseconds alerts = ses.pop_alerts() for a in alerts: - print a.message() + print(a.message()) + + st = h.status() + print(st.next_announce) + print(st.name) + print(st.errc.message()) + print(st.pieces) + print(st.last_seen_complete) + print(st.completed_time) + print(st.progress) + print(st.num_pieces) + print(st.distributed_copies) + print(st.paused) + print(st.info_hash) class test_bencoder(unittest.TestCase):