def test_help(capsys): """Capture and verify expected help info""" # --help does SystemExit so we need to catch it try: photos.main(arg_list('-h')) except SystemExit: pass verify(capsys, 'help')
def test_interactive(capsys, monkeypatch): """Verify series of interactive album ids""" monkeypatch.setattr(photos, 'get_photos', get_photos_mock) patch_input(monkeypatch, response=['2', '4', '0']) photos.main([]) verify(capsys, 'interactive_test')
def test_bad_albumid_interactive(capsys, monkeypatch): """Verify handling of invalid Album id in interactive mode""" patch_input(monkeypatch, response=['1', 'bad', '0']) photos.main([]) verify(capsys, 'bad_album_id_interactive')
def test_bad_albumid(capsys): """Verify handling of invalid Album id""" photos.main(arg_list('x')) verify(capsys, 'bad_album_id')
def test_101(capsys): """Verify non-existing Album number with debug enabled""" photos.main(arg_list('101 -d')) verify(capsys, 'album_101')
def test_35_100_max20(capsys, monkeypatch): """Verify multiple Album ids with max row number for each""" monkeypatch.setattr(photos, 'get_photos', get_photos_mock) photos.main(arg_list('35 100 -n 20')) verify(capsys, 'album_35+100_max20')
def test_3_bad_grep(capsys, monkeypatch): """Verify handling of invalid grep pattern""" monkeypatch.setattr(photos, 'get_photos', get_photos_mock) photos.main(arg_list('3 --grep "][" --rows --pretty')) verify(capsys, 'album_3_bad_grep')
def test_3_grep_nomatch(capsys, monkeypatch): """Verify row filtering with no matches""" monkeypatch.setattr(photos, 'get_photos', get_photos_mock) photos.main(arg_list('3 --grep NOMATCH --rows --pretty')) verify(capsys, 'album_3_grep_nomatch')
def test_3_max5(capsys, monkeypatch): """Verify first 5 rows of Album 3 with relative row numbers output""" monkeypatch.setattr(photos, 'get_photos', get_photos_mock) photos.main(arg_list('3 -n 5 --rows')) verify(capsys, 'album_3_max5_rows')
def test_2_max5(capsys, monkeypatch): """Verify first 5 rows of Album 2 in prettyTable format""" monkeypatch.setattr(photos, 'get_photos', get_photos_mock) photos.main(arg_list('2 -n 5 --pretty')) verify(capsys, 'album_2_max5_pretty')
def test_1(capsys, monkeypatch): """Verify Album 1""" monkeypatch.setattr(photos, 'get_photos', get_photos_mock) photos.main(arg_list('1')) verify(capsys, 'album_1')
def test_0(capsys): """Verify expected response from album id of zero""" photos.main(arg_list('0')) verify(capsys, 'album_0')
def test_exit_with_two_empty_returns(capsys, monkeypatch): """Verify exit via two empty returns""" patch_input(monkeypatch, response=['', '']) photos.main([]) verify(capsys, 'exit_with_two_empty_returns')
def test_no_args(capsys, monkeypatch): """Verify no argument behavior""" patch_input(monkeypatch, response='q') photos.main([]) verify(capsys, 'no_args')
def test_timeout(capsys): """Verify handling of timeout accessing URL""" photos.main(arg_list('99 -t .01')) verify(capsys, 'timeout_test')
def test_3_grep_qui(capsys, monkeypatch): """Verify row filtering with expected matches""" monkeypatch.setattr(photos, 'get_photos', get_photos_mock) photos.main(arg_list('3 --grep iste --rows --pretty')) verify(capsys, 'album_3_grep_qui')
def test_bad_url(capsys, monkeypatch): """Verify handling of bad or unrecognized URL""" patch_url(monkeypatch, 'x') photos.main(['1']) verify(capsys, 'bad_url')
import sys import os import b_w import photos if len(sys.argv) > 2: print('You have specified too many arguments') sys.exit() elif len(sys.argv) < 2: print('Enter path to an image.\nExample: python main.py imgs_0/img_0.jpg') sys.exit() elif not os.path.isfile(sys.argv[1]): print('Enter valid path to an image') sys.exit() elif sys.argv[1].endswith('jpg'): b_w.main(sys.argv[1]) else: photos.main(sys.argv[1])