psss / python-nitrate

Python API for the Nitrate test case management system
GNU Lesser General Public License v2.1
9 stars 25 forks source link

float as a prarameter of listed() function #28

Closed ZelenyMartin closed 3 years ago

ZelenyMartin commented 3 years ago
Error in atexit._run_exitfuncs:
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/nitrate/cache.py", line 400, in exit
    self.save()
  File "/usr/lib/python3.6/site-packages/nitrate/cache.py", line 259, in save
    log.cache("Cache dump stats:\n" + self.stats().strip())
  File "/usr/lib/python3.6/site-packages/nitrate/cache.py", line 520, in stats
    human(current_class._expiration))
  File "/usr/lib/python3.6/site-packages/nitrate/utils.py", line 151, in human
    for period in ["year", "month", "day", "hour", "minute", "second"]
  File "/usr/lib/python3.6/site-packages/nitrate/utils.py", line 153, in <listcomp>
    or time.seconds == time.days == 0 and period == "second"])
  File "/usr/lib/python3.6/site-packages/nitrate/utils.py", line 56, in listed
    items = list(items)
TypeError: 'float' object is not iterable

Crashes in utils.py, line 56 when items is type of float:

# Convert items to list if necessary
if isinstance(items, int):
    items = range(items)
elif not isinstance(items, list):
    items = list(items)

The float maybe came from:

def human(time):
    """ Convert timedelta into a human readable format """
    count = {}
    count["year"] = time.days / 365
    count["month"] = (time.days - 365 * count["year"]) / 30
    count["day"] = 0 if count["year"] > 0 else time.days % 30
    count["hour"] = time.seconds / 3600
    count["minute"] = (time.seconds - 3600 * count["hour"]) / 60
    count["second"] = (
            time.seconds - 3600 * count["hour"] - 60 * count["minute"])
    return listed([
            listed(count[period], period)
            for period in ["year", "month", "day", "hour", "minute", "second"]
            if count[period] > 0
            or time.seconds == time.days == 0 and period == "second"])