Changeset View
Changeset View
Standalone View
Standalone View
swh/deposit/tests/test_utils.py
# Copyright (C) 2018 The Software Heritage developers | # Copyright (C) 2018 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import unittest | import unittest | ||||
from nose.tools import istest | |||||
from swh.deposit import utils | from swh.deposit import utils | ||||
class UtilsTestCase(unittest.TestCase): | class UtilsTestCase(unittest.TestCase): | ||||
"""Utils library | """Utils library | ||||
""" | """ | ||||
@istest | def test_merge(self): | ||||
def merge(self): | |||||
"""Calling utils.merge on dicts should merge without losing information | """Calling utils.merge on dicts should merge without losing information | ||||
""" | """ | ||||
d0 = { | d0 = { | ||||
'author': 'someone', | 'author': 'someone', | ||||
'license': [['gpl2']], | 'license': [['gpl2']], | ||||
'a': 1 | 'a': 1 | ||||
} | } | ||||
Show All 27 Lines | def test_merge(self): | ||||
'someone', 'author0', {'name': 'author1'}, 'else', 'no one'], | 'someone', 'author0', {'name': 'author1'}, 'else', 'no one'], | ||||
'b': { | 'b': { | ||||
'1': '2', | '1': '2', | ||||
'2': '3', | '2': '3', | ||||
} | } | ||||
} | } | ||||
self.assertEquals(actual_merge, expected_merge) | self.assertEquals(actual_merge, expected_merge) | ||||
@istest | def test_merge_2(self): | ||||
def merge_2(self): | |||||
d0 = { | d0 = { | ||||
'license': 'gpl2', | 'license': 'gpl2', | ||||
'runtime': { | 'runtime': { | ||||
'os': 'unix derivative' | 'os': 'unix derivative' | ||||
} | } | ||||
} | } | ||||
d1 = { | d1 = { | ||||
Show All 9 Lines | def test_merge_2(self): | ||||
}, | }, | ||||
'GNU/Linux' | 'GNU/Linux' | ||||
], | ], | ||||
} | } | ||||
actual = utils.merge(d0, d1) | actual = utils.merge(d0, d1) | ||||
self.assertEqual(actual, expected) | self.assertEqual(actual, expected) | ||||
@istest | def test_merge_edge_cases(self): | ||||
def merge_edge_cases(self): | |||||
input_dict = { | input_dict = { | ||||
'license': ['gpl2', 'gpl3'], | 'license': ['gpl2', 'gpl3'], | ||||
'runtime': [ | 'runtime': [ | ||||
{ | { | ||||
'os': 'unix derivative' | 'os': 'unix derivative' | ||||
}, | }, | ||||
'GNU/Linux' | 'GNU/Linux' | ||||
], | ], | ||||
} | } | ||||
# against empty dict | # against empty dict | ||||
actual = utils.merge(input_dict, {}) | actual = utils.merge(input_dict, {}) | ||||
self.assertEqual(actual, input_dict) | self.assertEqual(actual, input_dict) | ||||
# against oneself | # against oneself | ||||
actual = utils.merge(input_dict, input_dict, input_dict) | actual = utils.merge(input_dict, input_dict, input_dict) | ||||
self.assertEqual(input_dict, input_dict) | self.assertEqual(input_dict, input_dict) | ||||
@istest | def test_merge_one_dict(self): | ||||
def merge_one_dict(self): | |||||
"""Merge one dict should result in the same dict value | """Merge one dict should result in the same dict value | ||||
""" | """ | ||||
input_and_expected = {'anything': 'really'} | input_and_expected = {'anything': 'really'} | ||||
actual = utils.merge(input_and_expected) | actual = utils.merge(input_and_expected) | ||||
self.assertEqual(actual, input_and_expected) | self.assertEqual(actual, input_and_expected) | ||||
@istest | def test_merge_raise(self): | ||||
def merge_raise(self): | |||||
"""Calling utils.merge with any no dict argument should raise | """Calling utils.merge with any no dict argument should raise | ||||
""" | """ | ||||
d0 = { | d0 = { | ||||
'author': 'someone', | 'author': 'someone', | ||||
'a': 1 | 'a': 1 | ||||
} | } | ||||
Show All 12 Lines |