Skip to content

Commit

Permalink
Issue #26: Extract dates and match different date files (TestFormatEx…
Browse files Browse the repository at this point in the history
…tra)
  • Loading branch information
Nekmo committed Sep 26, 2018
1 parent c532377 commit b407ff3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
10 changes: 9 additions & 1 deletion dirhunt/tests/test_url_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from dirhunt.sessions import Sessions
from dirhunt.url import Url
from dirhunt.url_info import UrlInfo, sizeof_fmt, DEFAULT_UNKNOWN_SIZE, UrlsInfo
from dirhunt.url_info import UrlInfo, sizeof_fmt, DEFAULT_UNKNOWN_SIZE, UrlsInfo, format_extra
from dirhunt.tests._compat import patch, Mock


Expand All @@ -26,6 +26,14 @@ def test_yib(self):
self.assertEqual(sizeof_fmt(1024 ** 8), '1YiB')


class TestFormatExtra(unittest.TestCase):
def test_without_length(self):
self.assertEqual(format_extra({'created_at': 'foo', 'filesize': 'bar'}), '[foo bar]')

def test_with_length(self):
self.assertEqual(format_extra({'created_at': 'foo', 'filesize': 'bar'}, 12), '[foo bar ]')


class TestUrlInfo(unittest.TestCase):
url = 'https://domain.com/foo.php'

Expand Down
3 changes: 2 additions & 1 deletion dirhunt/url_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def sizeof_fmt(num, suffix='B'):

def format_extra(extra, length=0):
length = max(0, length - 2)
return ('[{:<%d}]' % length).format(' '.join(map(itemgetter(1), sorted(extra.items()))))
return ('[{:<%d}]' % length).format(' '.join(map(itemgetter(1), sorted(extra.items(),
key=lambda x: EXTRA_ORDER.index(x[0])))))


class UrlInfo(object):
Expand Down

0 comments on commit b407ff3

Please sign in to comment.