File tree Expand file tree Collapse file tree 3 files changed +38
-11
lines changed Expand file tree Collapse file tree 3 files changed +38
-11
lines changed Original file line number Diff line number Diff line change 11import datetime
2+ import shutil
23from pathlib import Path
34from typing import Any , Dict , Optional
45
6+ import requests
57from darwin .dataset .identifier import DatasetIdentifier
6- from requests import Response
78
89
910class Release :
@@ -191,15 +192,9 @@ def download_zip(self, path: Path) -> Path:
191192 if not self .url :
192193 raise ValueError ("Release must have a valid url to download the zip." )
193194
194- from darwin .client import Client
195-
196- config_path : Path = Path .home () / ".darwin" / "config.yaml"
197- client : Client = Client .from_config (config_path = config_path , team_slug = self .team_slug )
198-
199- data : Response = client .fetch_binary (self .url )
200- with open (path , "wb" ) as download_file :
201- for chunk in data .iter_content (chunk_size = 8192 ):
202- download_file .write (chunk )
195+ with requests .get (self .url , stream = True ) as response :
196+ with open (path , "wb" ) as download_file :
197+ shutil .copyfileobj (response .raw , download_file )
203198
204199 return path
205200
Original file line number Diff line number Diff line change 1- __version__ = "0.7.11 "
1+ __version__ = "0.7.12 "
Original file line number Diff line number Diff line change 1+ import shutil
2+ from unittest .mock import patch
3+
4+ import requests
5+ from darwin .dataset .release import Release
6+ from tests .fixtures import *
7+
8+
9+ @pytest .fixture
10+ def release (dataset_slug : str , team_slug : str ) -> Release :
11+ return Release (
12+ dataset_slug = dataset_slug ,
13+ team_slug = team_slug ,
14+ version = "latest" ,
15+ name = "test" ,
16+ url = "http://test.v7labs.com/" ,
17+ export_date = "now" ,
18+ image_count = None ,
19+ class_count = None ,
20+ available = True ,
21+ latest = True ,
22+ format = "darwin" ,
23+ )
24+
25+
26+ def describe_release ():
27+ def it_downloads_zip (release : Release , tmp_path : Path ):
28+ with patch .object (requests , "get" ) as get :
29+ with patch .object (shutil , "copyfileobj" ) as copyfileobj :
30+ release .download_zip (tmp_path / "test.zip" )
31+ get .assert_called_once_with ("http://test.v7labs.com/" , stream = True )
32+ copyfileobj .assert_called_once ()
You can’t perform that action at this time.
0 commit comments