Skip to content

Commit

Permalink
Merge pull request #219 from AndreyNikiforov/bug/tz
Browse files Browse the repository at this point in the history
fixes tz-related tests for mac and windows
  • Loading branch information
AndreyNikiforov authored Nov 8, 2020
2 parents b976dfa + 45bc330 commit a61ae65
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 20 deletions.
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ COPY requirements-dev.txt .
COPY scripts/install_deps scripts/install_deps
RUN scripts/install_deps
COPY . .
ENV TZ="America/Los_Angeles"
RUN scripts/test
RUN scripts/lint

Expand Down
2 changes: 1 addition & 1 deletion icloudpd/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ def download_photo(counter, photo):
(".jpg", ".jpeg")) and not exif_datetime.get_photo_exif(download_path):
# %Y:%m:%d looks wrong but it's the correct format
date_str = created_date.strftime(
"%Y:%m:%d %H:%M:%S")
"%Y-%m-%d %H:%M:%S%z")
logger.debug(
"Setting EXIF timestamp for %s: %s",
download_path,
Expand Down
Binary file added tests/fixtures/中文/2018/07/31/IMG_7409.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 6 additions & 13 deletions tests/test_download_photos.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,6 @@ def test_download_and_skip_existing_photos(self):

assert result.exit_code == 0

@pytest.mark.skipif(sys.platform == 'win32',
reason="does not run on windows -- wrong dates")
@pytest.mark.skipif(sys.platform == 'darwin',
reason="does not run on macos -- wrong dates")
def test_download_photos_and_set_exif(self):
base_dir = os.path.normpath("tests/fixtures/Photos")
if os.path.exists(base_dir):
Expand Down Expand Up @@ -174,9 +170,10 @@ def mocked_download(self, size):
f"INFO Downloading {os.path.join(base_dir, os.path.normpath('2018/07/31/IMG_7409.JPG'))}",
self._caplog.text,
)
# YYYY:MM:DD is the correct format.
# 2018:07:31 07:22:24 utc
expectedDatetime = datetime.datetime(2018,7,31,7,22,24,tzinfo=datetime.timezone.utc).astimezone().strftime("%Y-%m-%d %H:%M:%S%z")
self.assertIn(
f"DEBUG Setting EXIF timestamp for {os.path.join(base_dir, os.path.normpath('2018/07/31/IMG_7409.JPG'))}: 2018:07:31 07:22:24", # TODO On windows it is picked as 00:22:24
f"DEBUG Setting EXIF timestamp for {os.path.join(base_dir, os.path.normpath('2018/07/31/IMG_7409.JPG'))}: {expectedDatetime}",
self._caplog.text,
)
self.assertIn(
Expand Down Expand Up @@ -296,8 +293,6 @@ def test_skip_existing_downloads(self):
)
assert result.exit_code == 0

@pytest.mark.skipif(sys.platform == 'win32',
reason="requires large timeout on windows to create big files")
def test_until_found(self):
base_dir = os.path.normpath("tests/fixtures/Photos")
if os.path.exists(base_dir):
Expand Down Expand Up @@ -1162,10 +1157,6 @@ def mocked_download(self, size):
assert result.exit_code == 0


@pytest.mark.skipif(sys.platform == 'win32',
reason="does not run on windows -- wrong dates")
@pytest.mark.skipif(sys.platform == 'darwin',
reason="does not run on macos -- wrong dates")
def test_download_photos_and_set_exif_exceptions(self):
base_dir = os.path.normpath("tests/fixtures/Photos")
if os.path.exists(base_dir):
Expand Down Expand Up @@ -1212,8 +1203,10 @@ def test_download_photos_and_set_exif_exceptions(self):
f"INFO Downloading {os.path.join(base_dir, os.path.normpath('2018/07/31/IMG_7409.JPG'))}",
self._caplog.text,
)
# 2018:07:31 07:22:24 utc
expectedDatetime = datetime.datetime(2018,7,31,7,22,24,tzinfo=datetime.timezone.utc).astimezone().strftime("%Y-%m-%d %H:%M:%S%z")
self.assertIn(
f"DEBUG Setting EXIF timestamp for {os.path.join(base_dir, os.path.normpath('2018/07/31/IMG_7409.JPG'))}: 2018:07:31 07:22:24", # TODO On windows it is picked as 00:22:24
f"DEBUG Setting EXIF timestamp for {os.path.join(base_dir, os.path.normpath('2018/07/31/IMG_7409.JPG'))}: {expectedDatetime}",
self._caplog.text,
)
self.assertIn(
Expand Down
11 changes: 5 additions & 6 deletions tests/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@
from freezegun import freeze_time
import pytest
from icloudpd.logger import setup_logger, IPDLogger
import datetime


class LoggerTestCase(TestCase):
# Tests the formatter that is set up in setup_logger()
@pytest.mark.skipif(sys.platform == 'win32',
reason="does not run on windows -- wrong dates")
@pytest.mark.skipif(sys.platform == 'darwin',
reason="does not run on macos -- wrong dates")
@freeze_time("2018-01-01 00:00")
@freeze_time("2018-01-01 00:00:00-0000")
def test_logger_output(self):
logger = setup_logger()
test_logger = logging.getLogger("icloudpd-test")
Expand All @@ -27,7 +24,9 @@ def test_logger_output(self):
test_logger.debug(u"Test debug output")
test_logger.error(u"Test error output")
output = string_io.getvalue().strip()
self.assertIn("2018-01-01", output)
# 2018:01:01 00:00:00 utc
expectedDatetime = datetime.datetime(2018,1,1,0,0,0,tzinfo=datetime.timezone.utc).astimezone().strftime("%Y-%m-%d %H:%M:%S")
self.assertIn(expectedDatetime, output)
self.assertIn("INFO Test info output", output)
self.assertIn("DEBUG Test debug output", output)
self.assertIn("ERROR Test error output", output)
Expand Down

0 comments on commit a61ae65

Please sign in to comment.