mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-07-23 22:17:49 +08:00
@@ -50,7 +50,11 @@ class ListUtils:
|
||||
if not any(isinstance(sublist, list) for sublist in nested_list):
|
||||
return nested_list
|
||||
|
||||
return [item for sublist in nested_list if isinstance(sublist, list) for item in sublist]
|
||||
return [
|
||||
item
|
||||
for sublist in nested_list
|
||||
for item in (sublist if isinstance(sublist, list) else [sublist])
|
||||
]
|
||||
|
||||
|
||||
class SetUtils:
|
||||
|
||||
15
tests/test_structures.py
Normal file
15
tests/test_structures.py
Normal file
@@ -0,0 +1,15 @@
|
||||
from unittest import TestCase
|
||||
|
||||
from app.utils.structures import ListUtils
|
||||
|
||||
|
||||
class ListUtilsTest(TestCase):
|
||||
def test_flatten_keeps_scalar_items_in_mixed_list(self):
|
||||
self.assertEqual(ListUtils.flatten([1, [2, 3], 4]), [1, 2, 3, 4])
|
||||
|
||||
def test_flatten_returns_plain_list_unchanged(self):
|
||||
source = [1, 2, 3]
|
||||
self.assertEqual(ListUtils.flatten(source), source)
|
||||
|
||||
def test_flatten_rejects_non_list_input(self):
|
||||
self.assertEqual(ListUtils.flatten("1,2,3"), [])
|
||||
Reference in New Issue
Block a user