Skip to content

Commit

Permalink
Fix BatchRunner method renaming causing tests to fail
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Larralde committed Mar 31, 2018
1 parent ad2762d commit cdbbb34
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion instalooter/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def main(argv=None, stream=None):
if args['batch']:
with open(args['<batch_file>']) as batch_file:
batch_runner = BatchRunner(batch_file, args)
batch_runner.runAll()
batch_runner.run_all()
return 0

# Login if requested
Expand Down
5 changes: 3 additions & 2 deletions instalooter/cli/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import getpass
import logging

from . import logutils
from ..looters import InstaLooter


Expand All @@ -18,6 +19,6 @@ def login(args):
password = args['--password'] or getpass.getpass()
InstaLooter._login(username, password)
if not args['--quiet']:
logger.log(logging.SUCCESS, 'Logged in.')
logger.log(logutils.SUCCESS, 'Logged in.')
elif not args['--quiet']:
logger.log(logging.SUCCESS, "Already logged in.")
logger.log(logutils.SUCCESS, "Already logged in.")
2 changes: 2 additions & 0 deletions instalooter/cli/threadutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

from ..worker import InstaDownloader


def threads_force_join():
for t in threading.enumerate():
if isinstance(t, InstaDownloader):
t.terminate()
t.join()


def threads_count():
return sum(isinstance(t, InstaDownloader) for t in threading.enumerate())
14 changes: 7 additions & 7 deletions instalooter/looters.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ def _init_session(cls, session=None):
"""Initialise the given session and load class cookies to its jar.
Arguments:
session (~requests.Session): a `requests` session,
or `None` to create a new one.
session (~requests.Session, optional): a `requests`
session, or `None` to create a new one.
Returns:
~requests.Session: an initialised session instance.
"""
session = session or Session()
session.cookies = LWPCookieJar( # type: ignore
session.cookies = LWPCookieJar(
cls._cachefs.getsyspath(cls._COOKIE_FILE))
try:
typing.cast(CookieJar, session.cookies).load()
Expand All @@ -101,14 +101,14 @@ def _login(cls, username, password, session=None):
Arguments:
username (str): the username to log in with.
password (str): the password to log in with.
session (~requests.Session or None): the session to use,
session (~requests.Session, optional): the session to use,
or `None` to create a new session.
Note:
Code taken from LevPasha/instabot.py
"""
session = session or cls._init_session()
session = cls._init_session(session)
homepage = "https://www.instagram.com/"
login_url = "https://www.instagram.com/accounts/login/ajax/"
data = {'username': username, 'password': password}
Expand Down Expand Up @@ -156,7 +156,7 @@ def _logout(cls, session=None):
Code taken from LevPasha/instabot.py
"""
session = session or cls._init_session()
session = cls._init_session(session)
sessionid = cls._sessionid(session)
if sessionid is not None:
url = "https://www.instagram.com/accounts/logout/"
Expand Down Expand Up @@ -194,7 +194,7 @@ def _sessionid(cls, session=None):
"""
_session = cls._init_session(session)
_cookies = typing.cast(CookieJar, session.cookies)
_cookies = typing.cast(CookieJar, _session.cookies)
return next((ck.value for ck in _cookies
if ck.domain == "www.instagram.com"
and ck.name == "sessionid"
Expand Down
5 changes: 2 additions & 3 deletions tests/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from instalooter.batch import BatchRunner



class TestBatchRunner(unittest.TestCase):

def setUp(self):
Expand Down Expand Up @@ -42,8 +41,8 @@ def test_cli(self):

retcode = main(["batch", self.destfs.getsyspath('batch.ini')])
self.assertEqual(retcode, 0)
self.assertEqual(len(list(self.destfs.filterdir("/", ["*.jpg"]))), 6)

self.assertGreaterEqual(
len(list(self.destfs.filterdir("/", ["*.jpg"]))), 6)


def setUpModule():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def test_issue_125(self):
))
runner = BatchRunner(configfile)
self.assertEqual(
runner.getTargets(runner._get('Family', 'users')),
runner.get_targets(runner._get('Family', 'users')),
{'instagram': 'D:\\Instagram\\Profiles\\instagram',
'therock': 'D:\\Instagram\\Profiles\\therock'}
)
Expand Down

0 comments on commit cdbbb34

Please sign in to comment.