Skip to content

Commit

Permalink
Merge 0be2a16 into d53d3f3
Browse files Browse the repository at this point in the history
  • Loading branch information
vitorkusiaki committed Aug 19, 2017
2 parents d53d3f3 + 0be2a16 commit 8b76fd0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
15 changes: 12 additions & 3 deletions serenata_toolbox/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
class Datasets:
"""
This is a wrapper for three different classes that together handle the
datasets (locally and remotelly).
datasets (locally and remotely).
Datasets class takes one argument: the path to the local directory of the
dataset files (e.g. data/ or /tmp/serenata-data). The argument is optional
Expand Down Expand Up @@ -74,7 +74,16 @@ def fetch(filename, destination_path):
datasets = Datasets(destination_path)
return datasets.downloader.download(filename)

def fetch_latest_backup(destination_path):

def fetch_latest_backup(destination_path, force_all=False):
datasets = Datasets(destination_path)
files = datasets.downloader.LATEST

if force_all:
files = datasets.downloader.LATEST
else:
files = tuple(
f for f in datasets.downloader.LATEST
if not os.path.exists(destination_path, f)
)

return datasets.downloader.download(files)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,5 @@
'serenata_toolbox.datasets'
],
url=REPO_URL,
version='12.0.6'
version='12.2.0'
)
24 changes: 17 additions & 7 deletions tests/unit/test_datasets.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from unittest import TestCase
from unittest.mock import call, patch, MagicMock
from unittest.mock import call, patch

from serenata_toolbox.datasets import Datasets, fetch, fetch_latest_backup

Expand Down Expand Up @@ -67,12 +67,6 @@ def test_upload_all(self, downloader, remote, local):

class TestFetch(TestCase):

@patch('serenata_toolbox.datasets.Datasets')
def test_fetch(self, datasets):
fetch('file.xz', 'test')
datasets.assert_called_once_with('test')
datasets.return_value.downloader.download.assert_called_once_with('file.xz')

@patch('serenata_toolbox.datasets.Datasets')
def test_fetch(self, datasets):
fetch('file.xz', 'test')
Expand All @@ -83,3 +77,19 @@ def test_fetch(self, datasets):
def test_fetch_latest_backup(self, datasets):
fetch_latest_backup('test')
self.assertTrue(datasets.return_value.downloader.download.called)

@patch('os.path.exists')
@patch('serenata_toolbox.datasets.Datasets')
def test_fetch_latest_backup_only_when_missing(self, datasets, os_path_exists):
datasets().downloader.LATEST = ('file1', 'file2', 'file3')
os_path_exists.side_effect = [False, True, False]
fetch_latest_backup('test')
datasets.return_value.downloader.download.assert_called_once_with(('file1', 'file3'))

@patch('os.path.exists')
@patch('serenata_toolbox.datasets.Datasets')
def test_fetch_latest_backup_with_force_all(self, datasets, os_path_exists):
datasets().downloader.LATEST = ('file1', 'file2', 'file3')
os_path_exists.side_effect = [False, True, False]
fetch_latest_backup('test', force_all=True)
datasets.return_value.downloader.download.assert_called_once_with(('file1', 'file2', 'file3'))

0 comments on commit 8b76fd0

Please sign in to comment.