Merge pull request #365 from arvidn/python-fix

extend python binding unit test and fix bugs in it
This commit is contained in:
Arvid Norberg 2016-01-06 08:15:09 -05:00
commit 18980e65a9
4 changed files with 35 additions and 2 deletions

View File

@ -6,8 +6,10 @@
#include <boost/date_time/posix_time/posix_time_types.hpp>
#include "optional.hpp"
#include <boost/version.hpp>
#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<lt::milliseconds>(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<boost::posix_time::ptime>();
}

View File

@ -388,7 +388,7 @@ namespace
#endif
#ifndef TORRENT_NO_DEPRECATE
boost::shared_ptr<alert const>
boost::shared_ptr<alert>
#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)();

View File

@ -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)

View File

@ -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):