Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/gnu/tests/test_lister.py
- This file was added.
# Copyright (C) 2019 the Software Heritage developers | |||||
# License: GNU General Public License version 3, or any later version | |||||
# See top-level LICENSE file for more information | |||||
import json | |||||
import unittest | |||||
from swh.lister.gnu.lister import find_tarballs, remove_unnecessary_directories | |||||
class GNUListerTester(unittest.TestCase): | |||||
ardumont: Since those are new tests, try to write them more pytest like.
Those are old unittest like we… | |||||
def test_remove_unnecessary_directories(self): | |||||
f = open('swh/lister/gnu/tests/api_response.json') | |||||
api_response = json.load(f) | |||||
cleared_api_response = remove_unnecessary_directories(api_response) | |||||
for directory in cleared_api_response: | |||||
if directory['name'] not in ('gnu', 'old-gnu'): | |||||
self.assertFalse(True) | |||||
def test_find_tarballs(self): | |||||
f = open('swh/lister/gnu/tests/find_tarballs_output.json') | |||||
expected_list_of_all_tarballs = json.load(f) | |||||
f = open('swh/lister/gnu/tests/file_structure.json') | |||||
file_structure = json.load(f) | |||||
list_of_all_tarballs = [] | |||||
list_of_all_tarballs.extend( | |||||
find_tarballs(file_structure[0]['contents'], | |||||
"https://ftp.gnu.org/gnu/artanis/")) | |||||
list_of_all_tarballs.extend( | |||||
find_tarballs(file_structure[1]['contents'], | |||||
"https://ftp.gnu.org/old-gnu/xboard/")) | |||||
Done Inline ActionsHere I have made a JSON file(file_structure.json) which contains file structure of 2 packages. One chosen from gnu/ and other from old-gnu/, they are smartly chosen to check the ability of the code to list tarballs inside subfolders as well. Here I have combined the response for both the packages so that only one file (find_tarballs_output.json) can be used to store the correct answer. nahimilega: Here I have made a JSON file(file_structure.json) which contains file structure of 2 packages. | |||||
self.assertEqual( | |||||
list_of_all_tarballs, | |||||
expected_list_of_all_tarballs) |
Since those are new tests, try to write them more pytest like.
Those are old unittest like we try to move away from (we did not refactor yet the existing lister ones).
That means simply transform those class's method to function (and drop the class).
Keep the test_ in the function names.