Changeset - 469b16f3979a
[Not reviewed]
default
0 3 0
Mads Kiilerich - 6 years ago 2019-08-06 21:08:02
mads@kiilerich.com
vcs: drop get_total_seconds - we only support Python 2.7 which has timedelta.total_seconds()
3 files changed with 2 insertions and 31 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/vcs/utils/helpers.py
Show inline comments
 
@@ -218,18 +218,6 @@ def get_dict_for_attrs(obj, attrs):
 
    Returns dictionary for each attribute from given ``obj``.
 
    """
 
    data = {}
 
    for attr in attrs:
 
        data[attr] = getattr(obj, attr)
 
    return data
 

	
 

	
 
def get_total_seconds(timedelta):
 
    """
 
    Backported for Python 2.5.
 

	
 
    See http://docs.python.org/library/datetime.html.
 
    """
 
    return ((timedelta.microseconds + (
 
            timedelta.seconds +
 
            timedelta.days * 24 * 60 * 60
 
        ) * 10**6) / 10**6)
kallithea/lib/vcs/utils/progressbar.py
Show inline comments
 
# encoding: UTF-8
 
import sys
 
import datetime
 
import string
 

	
 
from kallithea.lib.vcs.utils.filesize import filesizeformat
 
from kallithea.lib.vcs.utils.helpers import get_total_seconds
 

	
 

	
 
class ProgressBarError(Exception):
 
    pass
 

	
 

	
 
@@ -84,13 +83,13 @@ class ProgressBar(object):
 

	
 
    def get_eta(self, current_time=None):
 
        if current_time is None:
 
            current_time = datetime.datetime.now()
 
        if self.step == 0:
 
            return datetime.timedelta()
 
        total_seconds = get_total_seconds(self.get_total_time())
 
        total_seconds = self.get_total_time().total_seconds()
 
        eta_seconds = total_seconds * self.steps / self.step - total_seconds
 
        return datetime.timedelta(seconds=int(eta_seconds))
 

	
 
    def get_rendered_eta(self):
 
        eta = self.get_eta()
 
        if not eta:
 
@@ -110,13 +109,13 @@ class ProgressBar(object):
 
        return '%s: %s/%s' % (self.steps_label, self.step, self.steps)
 

	
 
    def get_rendered_speed(self, step=None, total_seconds=None):
 
        if step is None:
 
            step = self.step
 
        if total_seconds is None:
 
            total_seconds = get_total_seconds(self.get_total_time())
 
            total_seconds = self.get_total_time().total_seconds()
 
        if step <= 0 or total_seconds <= 0:
 
            speed = '-'
 
        else:
 
            speed = filesizeformat(float(step) / total_seconds)
 
        return '%s: %s/s' % (self.speed_label, speed)
 

	
kallithea/tests/vcs/test_utils.py
Show inline comments
 
@@ -9,13 +9,12 @@ import datetime
 
import pytest
 

	
 
from kallithea.lib.vcs.utils.paths import get_dirs_for_path
 
from kallithea.lib.vcs.utils.helpers import get_dict_for_attrs
 
from kallithea.lib.vcs.utils.helpers import get_scm
 
from kallithea.lib.vcs.utils.helpers import get_scms_for_path
 
from kallithea.lib.vcs.utils.helpers import get_total_seconds
 
from kallithea.lib.vcs.utils.helpers import parse_changesets
 
from kallithea.lib.vcs.utils.helpers import parse_datetime
 
from kallithea.lib.vcs.utils import author_email, author_name
 
from kallithea.lib.vcs.utils.paths import get_user_home
 
from kallithea.lib.vcs.exceptions import VCSError
 

	
 
@@ -228,27 +227,12 @@ class TestGetDictForAttrs(object):
 
            'attrs': {'foo': 'bar'},
 
            'date': datetime.datetime(2010, 12, 31),
 
            'count': 1001,
 
        }
 

	
 

	
 
class TestGetTotalSeconds(object):
 

	
 
    def assertTotalSecondsEqual(self, timedelta, expected_seconds):
 
        result = get_total_seconds(timedelta)
 
        assert result == expected_seconds, \
 
            "We computed %s seconds for %s but expected %s" \
 
            % (result, timedelta, expected_seconds)
 

	
 
    def test_get_total_seconds_returns_proper_value(self):
 
        self.assertTotalSecondsEqual(datetime.timedelta(seconds=1001), 1001)
 

	
 
    def test_get_total_seconds_returns_proper_value_for_partial_seconds(self):
 
        self.assertTotalSecondsEqual(datetime.timedelta(seconds=50.65), 50.65)
 

	
 

	
 
class TestGetUserHome(object):
 

	
 
    @mock.patch.object(os, 'environ', {})
 
    def test_defaults_to_none(self):
 
        assert get_user_home() == ''
 

	
0 comments (0 inline, 0 general)