xmunoz / sodapy

Compare 26f6386 ... +0 ... 462587f

Coverage Reach

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.

Showing 2 of 5 files from the diff.

@@ -1,10 +1,10 @@
Loading
1 -
from io import StringIO, IOBase
2 -
import requests
3 1
import csv
2 +
from io import StringIO, IOBase
4 3
import json
5 4
import logging
6 -
import re
7 5
import os
6 +
import re
7 +
import requests
8 8
9 9
from sodapy.constants import DATASETS_PATH
10 10
import sodapy.utils as utils
@@ -74,7 +74,7 @@
Loading
74 74
            self.session.auth = (username, password)
75 75
        elif access_token:
76 76
            self.session.headers.update(
77 -
                {"Authorization": "OAuth {0}".format(access_token)}
77 +
                {"Authorization": "OAuth {}".format(access_token)}
78 78
            )
79 79
80 80
        if session_adapter:
@@ -214,26 +214,26 @@
Loading
214 214
        results = self._perform_request(
215 215
            "get", DATASETS_PATH, params=params + [("offset", offset)]
216 216
        )
217 -
        numResults = results["resultSetSize"]
217 +
        num_results = results["resultSetSize"]
218 218
        # no more results to fetch, or limit reached
219 219
        if (
220 -
            limit >= numResults
220 +
            limit >= num_results
221 221
            or limit == len(results["results"])
222 -
            or numResults == len(results["results"])
222 +
            or num_results == len(results["results"])
223 223
        ):
224 224
            return results["results"]
225 225
226 226
        if limit != 0:
227 227
            raise Exception(
228 228
                "Unexpected number of results returned from endpoint.\
229 -
                    Expected {0}, got {1}.".format(
229 +
                    Expected {}, got {}.".format(
230 230
                    limit, len(results["results"])
231 231
                )
232 232
            )
233 233
234 234
        # get all remaining results
235 235
        all_results = results["results"]
236 -
        while len(all_results) != numResults:
236 +
        while len(all_results) != num_results:
237 237
            offset += len(results["results"])
238 238
            results = self._perform_request(
239 239
                "get", DATASETS_PATH, params=params + [("offset", offset)]
@@ -336,20 +336,20 @@
Loading
336 336
            if has_assetid:
337 337
                base = utils.format_old_api_request(dataid=dataset_identifier)
338 338
                assetid = attachment["assetId"]
339 -
                resource = "{0}/files/{1}?download=true&filename={2}".format(
339 +
                resource = "{}/files/{}?download=true&filename={}".format(
340 340
                    base, assetid, attachment["filename"]
341 341
                )
342 342
            else:
343 343
                base = "/api/assets"
344 344
                assetid = attachment["blobId"]
345 -
                resource = "{0}/{1}?download=true".format(base, assetid)
345 +
                resource = "{}/{}?download=true".format(base, assetid)
346 346
347 -
            uri = "{0}{1}{2}".format(self.uri_prefix, self.domain, resource)
347 +
            uri = "{}{}{}".format(self.uri_prefix, self.domain, resource)
348 348
            utils.download_file(uri, file_path)
349 349
            files.append(file_path)
350 350
351 351
        logging.info(
352 -
            "The following files were downloaded:\n\t{0}".format("\n\t".join(files))
352 +
            "The following files were downloaded:\n\t%s", "\n\t".join(files)
353 353
        )
354 354
        return files
355 355
@@ -359,7 +359,7 @@
Loading
359 359
        This method publishes it.
360 360
        """
361 361
        base = utils.format_old_api_request(dataid=dataset_identifier)
362 -
        resource = "{0}/publication.{1}".format(base, content_type)
362 +
        resource = "{}/publication.{}".format(base, content_type)
363 363
364 364
        return self._perform_request("post", resource)
365 365
@@ -508,7 +508,7 @@
Loading
508 508
            )
509 509
        else:
510 510
            raise Exception(
511 -
                "Unrecognized payload {0}. Currently only list-, dictionary-,"
511 +
                "Unrecognized payload {}. Currently only list-, dictionary-,"
512 512
                " and file-types are supported.".format(type(payload))
513 513
            )
514 514
@@ -540,10 +540,10 @@
Loading
540 540
        if request_type not in request_type_methods:
541 541
            raise Exception(
542 542
                "Unknown request type. Supported request types are"
543 -
                ": {0}".format(", ".join(request_type_methods))
543 +
                ": {}".format(", ".join(request_type_methods))
544 544
            )
545 545
546 -
        uri = "{0}{1}{2}".format(self.uri_prefix, self.domain, resource)
546 +
        uri = "{}{}{}".format(self.uri_prefix, self.domain, resource)
547 547
548 548
        # set a timeout, just to be safe
549 549
        kwargs["timeout"] = self.timeout
@@ -563,18 +563,18 @@
Loading
563 563
        content_type = response.headers.get("content-type").strip().lower()
564 564
        if re.match(r"application\/(vnd\.geo\+)?json", content_type):
565 565
            return response.json()
566 -
        elif re.match(r"text\/csv", content_type):
566 +
        if re.match(r"text\/csv", content_type):
567 567
            csv_stream = StringIO(response.text)
568 -
            return [line for line in csv.reader(csv_stream)]
569 -
        elif re.match(r"application\/rdf\+xml", content_type):
568 +
            return list(csv.reader(csv_stream))
569 +
        if re.match(r"application\/rdf\+xml", content_type):
570 570
            return response.content
571 -
        elif re.match(r"text\/plain", content_type):
571 +
        if re.match(r"text\/plain", content_type):
572 572
            try:
573 573
                return json.loads(response.text)
574 574
            except ValueError:
575 575
                return response.text
576 -
        else:
577 -
            raise Exception("Unknown response format: {0}".format(content_type))
576 +
577 +
        raise Exception("Unknown response format: {}".format(content_type))
578 578
579 579
    def close(self):
580 580
        """

@@ -26,7 +26,7 @@
Loading
26 26
        except ValueError:
27 27
            more_info = None
28 28
        if more_info and more_info.lower() != response.reason.lower():
29 -
            http_error_msg += ".\n\t{0}".format(more_info)
29 +
            http_error_msg += ".\n\t{}".format(more_info)
30 30
        raise requests.exceptions.HTTPError(http_error_msg, response=response)
31 31
32 32
@@ -45,27 +45,25 @@
Loading
45 45
46 46
    if dataid is not None:
47 47
        if content_type is not None:
48 -
            return "{0}/{1}.{2}".format(OLD_API_PATH, dataid, content_type)
49 -
        else:
50 -
            return "{0}/{1}".format(OLD_API_PATH, dataid)
51 -
    else:
52 -
        if content_type is not None:
53 -
            return "{0}.{1}".format(OLD_API_PATH, content_type)
54 -
        else:
55 -
            raise Exception(
56 -
                "This method requires at least a dataset_id or content_type."
57 -
            )
48 +
            return "{}/{}.{}".format(OLD_API_PATH, dataid, content_type)
49 +
        return "{}/{}".format(OLD_API_PATH, dataid)
50 +
51 +
    if content_type is not None:
52 +
        return "{}.{}".format(OLD_API_PATH, content_type)
53 +
54 +
    raise Exception(
55 +
        "This method requires at least a dataset_id or content_type."
56 +
    )
58 57
59 58
60 59
def format_new_api_request(dataid=None, row_id=None, content_type=None):
61 60
    if dataid is not None:
62 61
        if content_type is not None:
63 62
            if row_id is not None:
64 -
                return "{0}{1}/{2}.{3}".format(
63 +
                return "{}{}/{}.{}".format(
65 64
                    DEFAULT_API_PATH, dataid, row_id, content_type
66 65
                )
67 -
            else:
68 -
                return "{0}{1}.{2}".format(DEFAULT_API_PATH, dataid, content_type)
66 +
            return "{}{}.{}".format(DEFAULT_API_PATH, dataid, content_type)
69 67
70 68
    raise Exception("This method requires at least a dataset_id or content_type.")
71 69

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
sodapy 81.20%
Project Totals (5 files) 81.20%
Loading