# Buggy code
def sesscb_states_callback(self, states_list):
    """
    This method is periodically (every second) called with a list of the download states of the active downloads.
    """
    self.state_cb_count += 1

    # Check to see if a download has finished
    new_active_downloads = []
    do_checkpoint = False
    seeding_download_list = []

    for ds in states_list:
        state = ds.get_status()
        download = ds.get_download()
        tdef = download.get_def()
        safename = tdef.get_name_as_unicode()

        if state == DLSTATUS_DOWNLOADING:
            new_active_downloads.append(safename)
        elif state == DLSTATUS_STOPPED_ON_ERROR:
            self._logger.error("Error during download: %s", repr(ds.get_error()))
            self.downloads.get(tdef.get_infohash()).stop()
            self.session.notifier.notify(
                NTFY_TORRENT, NTFY_ERROR, tdef.get_infohash(), repr(ds.get_error())
            )
        elif state == DLSTATUS_SEEDING:
            seeding_download_list.append(
                {"infohash": tdef.get_infohash(), "download": download}
            )

            if safename in self.previous_active_downloads:
                self.session.notifier.notify(
                    NTFY_TORRENT, NTFY_FINISHED, tdef.get_infohash(), safename
                )
                do_checkpoint = True

            elif download.get_hops() == 0 and download.get_safe_seeding():
                hops = self.session.config.get_default_number_hops()
                self._logger.info(
                    "Moving completed torrent to tunneled session %d for hidden seeding %r",
                    hops,
                    download,
                )
                yield self.session.remove_download(download)

                # copy the old download_config and change the hop count
                dscfg = download.copy()
                dscfg.set_hops(hops)

                self.session.start_download_from_tdef(tdef, dscfg)

    self.previous_active_downloads = new_active_downloads
    if do_checkpoint:
        self.session.checkpoint_downloads()

    if self.state_cb_count % 4 == 0 and self.tunnel_community:
        self.tunnel_community.monitor_downloads(states_list)

    returnValue([])


# Traceback (AssertionError)
Tuples differ: (2, ('127.0.0.1', [5, 4, 3, 2,... != (2, ('127.0.0.1', [5, 4, 3, 2,...

First differing element 2:
u'None'
''

- (2, ('127.0.0.1', [5, 4, 3, 2, 1]), u'None')
?                                     - ----

+ (2, ('127.0.0.1', [5, 4, 3, 2, 1]), '')
Stacktrace

Traceback (most recent call last):
File "c:\python27\lib\unittest\case.py", line 329, in run
testMethod()
File "C:\workspace\jenkins\workspace\GH_Tribler_PR_tests_win64\tribler\Tribler\Test\test_as_server.py", line 58, in check
result = fun(*argv, **kwargs)
File "C:\workspace\jenkins\workspace\GH_Tribler_PR_tests_win64\tribler\Tribler\Test\Core\Upgrade\test_config_upgrade_70_71.py", line 33, in test_read_test_libtribler_conf
self.assertEqual(result_config.get_anon_proxy_settings(), (2, ("127.0.0.1", [5, 4, 3, 2, 1]), ''))
File "c:\python27\lib\unittest\case.py", line 513, in assertEqual
assertion_func(first, second, msg=msg)
File "c:\python27\lib\unittest\case.py", line 753, in assertTupleEqual
self.assertSequenceEqual(tuple1, tuple2, msg, seq_type=tuple)
File "c:\python27\lib\unittest\case.py", line 724, in assertSequenceEqual
self.fail(msg)
File "c:\python27\lib\unittest\case.py", line 410, in fail
raise self.failureException(msg)
AssertionError: Tuples differ: (2, ('127.0.0.1', [5, 4, 3, 2,... != (2, ('127.0.0.1', [5, 4, 3, 2,...

First differing element 2:
u'None'
''

- (2, ('127.0.0.1', [5, 4, 3, 2, 1]), u'None')
?                                     - ----

+ (2, ('127.0.0.1', [5, 4, 3, 2, 1]), '')

# Fixed code
def sesscb_states_callback(self, states_list):
    """
    This method is periodically (every second) called with a list of the download states of the active downloads.
    """
    self.state_cb_count += 1

    # Check to see if a download has finished
    new_active_downloads = []
    do_checkpoint = False
    seeding_download_list = []

    for ds in states_list:
        state = ds.get_status()
        download = ds.get_download()
        tdef = download.get_def()
        safename = tdef.get_name_as_unicode()

        if state == DLSTATUS_DOWNLOADING:
            new_active_downloads.append(safename)
        elif state == DLSTATUS_STOPPED_ON_ERROR:
            self._logger.error("Error during download: %s", repr(ds.get_error()))
            self.downloads.get(tdef.get_infohash()).stop()
            self.session.notifier.notify(
                NTFY_TORRENT, NTFY_ERROR, tdef.get_infohash(), repr(ds.get_error())
            )
        elif state == DLSTATUS_SEEDING:
            seeding_download_list.append(
                {"infohash": tdef.get_infohash(), "download": download}
            )

            if safename in self.previous_active_downloads:
                self.session.notifier.notify(
                    NTFY_TORRENT, NTFY_FINISHED, tdef.get_infohash(), safename
                )
                do_checkpoint = True

    self.previous_active_downloads = new_active_downloads
    if do_checkpoint:
        self.session.checkpoint_downloads()

    if self.state_cb_count % 4 == 0 and self.tunnel_community:
        self.tunnel_community.monitor_downloads(states_list)

    return []