Skip to content

Commit

Permalink
contrib/ftp: add testcase for tempfile cleanup
Browse files Browse the repository at this point in the history
Also let test work in Python 3.
Also make the mtime offset larger because it fails in my timezone.
  • Loading branch information
jethron committed Aug 15, 2019
1 parent 921d560 commit c3ce5ae
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions test/_test_ftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@
import ftplib
import os
import shutil
import sys
from helpers import unittest
try:
from cStringIO import StringIO
except ImportError:
from io import StringIO
from io import BytesIO
def StringIO(s):
return BytesIO(s.encode('utf8'))

from luigi.contrib.ftp import RemoteFileSystem, RemoteTarget

Expand Down Expand Up @@ -180,11 +183,19 @@ def test_get(self):
with remotetarget.open('r') as fin:
self.assertEqual(fin.read(), "something to fill")

# check for cleaning temporary files
if sys.version_info >= (3, 2):
# cleanup uses tempfile.TemporaryDirectory only available in 3.2+
temppath = remotetarget._RemoteTarget__tmp_path
self.assertTrue(os.path.exists(temppath))
remotetarget = None # garbage collect remotetarget
self.assertFalse(os.path.exists(temppath))

# file is successfuly created
self.assertTrue(os.path.exists(local_filepath))

# test RemoteTarget with mtime
ts = datetime.datetime.now() - datetime.timedelta(minutes=2)
ts = datetime.datetime.now() - datetime.timedelta(days=2)
delayed_remotetarget = RemoteTarget(remote_file, HOST, username=USER, password=PWD, mtime=ts)
self.assertTrue(delayed_remotetarget.exists())

Expand Down

0 comments on commit c3ce5ae

Please sign in to comment.