+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 26 additions & 28 deletions nf_core/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,11 @@ def compare_remote_local(self):
for lwf in self.local_workflows:
if rwf.full_name == lwf.full_name:
rwf.local_wf = lwf
try:
if rwf.releases:
if rwf.releases[0]['tag_sha'] == lwf.commit_sha:
rwf.local_is_latest = True
else:
rwf.local_is_latest = False
except IndexError:
pass

def print_summary(self):
""" Print summary of all pipelines """
Expand Down Expand Up @@ -265,6 +263,7 @@ def pretty_date(time):
'just now', etc

Based on https://stackoverflow.com/a/1551394/713980
Adapted by sven1103
"""
from datetime import datetime
now = datetime.now()
Expand All @@ -275,28 +274,27 @@ def pretty_date(time):
second_diff = diff.seconds
day_diff = diff.days

if day_diff < 0:
return ''

if day_diff == 0:
if second_diff < 10:
return "just now"
if second_diff < 60:
return str(second_diff) + " seconds ago"
if second_diff < 120:
return "a minute ago"
if second_diff < 3600:
return str(second_diff / 60) + " minutes ago"
if second_diff < 7200:
return "an hour ago"
if second_diff < 86400:
return str(second_diff / 3600) + " hours ago"
if day_diff == 1:
return "Yesterday"
if day_diff < 7:
return str(day_diff) + " days ago"
if day_diff < 31:
return str(day_diff / 7) + " weeks ago"
if day_diff < 365:
return str(day_diff / 30) + " months ago"
return str(day_diff / 365) + " years ago"
pretty_msg = {
0: [(float('inf'), 1, 'from the future')],
1: [
(10, 1, "just now"),
(60, 1, "{sec} seconds ago"),
(120, 1, "a minute ago"),
(3600, 60, "{sec} minutes ago"),
(7200, 1, "an hour ago"),
(86400, 3600, "{sec} hours ago")
],
2: [(float('inf'), 1, 'yesterday')],
7: [(float('inf'), 1, '{days} days ago')],
31: [(float('inf'), 7, '{days} weeks ago')],
365: [(float('inf'), 30, '{days} months ago')],
float('inf'): [(float('inf'), 365, '{days} years ago')]
}

for days, seconds in pretty_msg.items():
if day_diff < days:
for sec in seconds:
if second_diff < sec[0]:
return sec[2].format(days=round(day_diff/sec[1], 1),
sec=round(second_diff/sec[1], 1))
return '... time is relative anyway'
70 changes: 64 additions & 6 deletions tests/test_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,72 @@
""" Tests covering the workflow listing code.
"""
import os
import time
import pytest
import unittest
import nf_core.list
from nose.tools import raises
from datetime import datetime

def test_working_listcall():
""" Test that listing pipelines works """
nf_core.list.list_workflows()
class TestLint(unittest.TestCase):
"""Class for list tests"""

def test_working_listcall_json():
""" Test that listing pipelines with JSON works """
nf_core.list.list_workflows(True)
def test_working_listcall(self):
""" Test that listing pipelines works """
nf_core.list.list_workflows()

def test_working_listcall_json(self):
""" Test that listing pipelines with JSON works """
nf_core.list.list_workflows(True)

def test_pretty_datetime(self):
""" Test that the pretty datetime function works """
now = datetime.now()
nf_core.list.pretty_date(now)
now_ts = time.mktime(now.timetuple())
nf_core.list.pretty_date(now_ts)

@raises(AssertionError)
def test_local_workflows_and_fail(self):
""" Test the local workflow class and try to get local
Nextflow workflow information """
loc_wf = nf_core.list.LocalWorkflow("myWF")
loc_wf.get_local_nf_workflow_details()

def test_local_workflows_compare_and_fail_silently(self):
""" Test the workflow class and try to compare local
and remote workflows """
wfs = nf_core.list.Workflows()
lwf_ex = nf_core.list.LocalWorkflow("myWF")
lwf_ex.full_name = 'my Workflow'
lwf_ex.commit_sha = "aw3s0meh1sh"

remote = {
'name': 'myWF',
'full_name': 'my Workflow',
'description': '...',
'archived': [],
'stargazers_count': 42,
'watchers_count': 6,
'forks_count': 7,
}

rwf_ex = nf_core.list.RemoteWorkflow(remote)
rwf_ex.commit_sha = "aw3s0meh1sh"
rwf_ex.releases = [{'tag_sha': "aw3s0meh1sh"}]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it 😀



wfs.local_workflows.append(lwf_ex)
wfs.remote_workflows.append(rwf_ex)
wfs.compare_remote_local()

self.assertEqual(rwf_ex.local_wf, lwf_ex)

rwf_ex.releases = []
rwf_ex.releases.append({'tag_sha': "noaw3s0meh1sh"})
wfs.compare_remote_local()

rwf_ex.full_name = "your Workflow"
wfs.compare_remote_local()

rwf_ex.releases = None
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载