Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

corrected typo and adjust indent in tests #274

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions google_images_download/google_images_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import re
import codecs
import socket
import imghdr

args_list = ["keywords", "keywords_from_file", "prefix_keywords", "suffix_keywords",
"limit", "format", "color", "color_type", "usage_rights", "size",
Expand Down Expand Up @@ -637,6 +638,17 @@ def download_image(self,image_url,image_format,main_directory,dir_name,count,pri
output_file = open(path, 'wb')
output_file.write(data)
output_file.close()

# extension check
with open(path, "rb") as f:
f = open(path, 'rb')
ext = imghdr.what(f)
# change extension when there's mismatch
if ext and image_format != ext:
os.rename(path, path[:path.rfind(".")+1]+ext)
image_name = image_name.replace(image_format, ext)
image_format = ext

if save_source:
list_path = main_directory + "/" + save_source + ".txt"
list_file = open(list_path,'a')
Expand Down
12 changes: 6 additions & 6 deletions tests/test_google_images_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,35 @@ def silent_remove_of_file(file):

def test_download_images_to_default_location():
start_time = time.time()
argumnets = {
arguments = {
"keywords": "Polar bears",
"limit": 5,
"print_urls": False
}
try:
temp = argumnets['output_folder']
temp = arguments['output_folder']
except KeyError:
pass
else:
assert False, "This test checks download to default location yet an output folder was provided"

output_folder_path = os.path.join(os.path.realpath('.'), 'downloads', '{}'.format(argumnets['keywords']))
output_folder_path = os.path.join(os.path.realpath('.'), 'downloads', '{}'.format(arguments['keywords']))
if os.path.exists(output_folder_path):
start_amount_of_files_in_output_folder = len([name for name in os.listdir(output_folder_path) if os.path.isfile(os.path.join(output_folder_path, name)) and os.path.getctime(os.path.join(output_folder_path, name)) < start_time])
else:
start_amount_of_files_in_output_folder = 0

response = google_images_download.googleimagesdownload()
response.download(argumnets)
response.download(arguments)
files_modified_after_test_started = [name for name in os.listdir(output_folder_path) if os.path.isfile(os.path.join(output_folder_path, name)) and os.path.getmtime(os.path.join(output_folder_path, name)) > start_time]
end_amount_of_files_in_output_folder = len(files_modified_after_test_started)
print(f"Files downloaded by test {__name__}:")
for file in files_modified_after_test_started:
print(os.path.join(output_folder_path, file))


# assert end_amount_of_files_in_output_folder - start_amount_of_files_in_output_folder == argumnets['limit']
assert end_amount_of_files_in_output_folder == argumnets['limit']
# assert end_amount_of_files_in_output_folder - start_amount_of_files_in_output_folder == arguments['limit']
assert end_amount_of_files_in_output_folder == arguments['limit']

print(f"Cleaning up all files downloaded by test {__name__}...")
for file in files_modified_after_test_started:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_sample.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sample Test passing with nose and pytest

def test_pass():
assert True, "dummy sample test"
assert True, "dummy sample test"