Repository: nagisc007/storybuilder

Issue:
Need to fix: nothing error in storyDB
空の要素で失敗
===

**Description**
StoryDBの引数で要素が空のタプルが含まれている時にerror発生。審査して作らないように対処。


Comments:

Patch:
diff --git a/builder/master.py b/builder/master.py
index 3a72f96..00a1f2a 100644
--- a/builder/master.py
+++ b/builder/master.py
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 """Story manager class.
 """
-from .sbutils import assert_isint, assert_isstr
+from .sbutils import assert_isint, assert_islist, assert_isstr
 from .action import _BaseAction, ActionGroup, TagAction
 from .enums import GroupType, LangType, TagType
 from .subject import Subject, Day, Item, Person, Stage, Word
@@ -119,34 +119,44 @@ class Master(dict):
         return ActionGroup(lang=lang, group_type=GroupType.SCENE, *tmp)
 
     def set_days(self, li: list):
+        assert_islist(li)
+
         for v in li:
             self.append_day(v[0], v[1:])
         return self
 
-    def set_db(self, persons: list, stages: list, days: list, items: list, words: list):
-        self.set_persons(persons)
-        self.set_stages(stages)
-        self.set_days(days)
-        self.set_items(items)
-        self.set_words(words)
+    def set_db(self, persons: list=None, stages: list=None, days: list=None, items: list=None, words: list=None):
+        self.set_persons(persons if persons else [])
+        self.set_stages(stages if stages else [])
+        self.set_days(days if days else [])
+        self.set_items(items if items else [])
+        self.set_words(words if words else [])
         return self
 
     def set_items(self, li: list):
+        assert_islist(li)
+
         for v in li:
             self.append_item(v[0], v[1:])
         return self
 
     def set_persons(self, li: list):
+        assert_islist(li)
+
         for v in li:
             self.append_person(v[0], v[1:])
         return self
 
     def set_stages(self, li: list):
+        assert_islist(li)
+
         for v in li:
             self.append_stage(v[0], v[1:])
         return self
 
     def set_words(self, li: list):
+        assert_islist(li)
+
         for v in li:
             self.append_word(v[0], v[1:])
         return self
diff --git a/builder/sbutils.py b/builder/sbutils.py
index c5e1219..d05a510 100644
--- a/builder/sbutils.py
+++ b/builder/sbutils.py
@@ -37,6 +37,12 @@ def assert_isint(ins) -> bool:
 
 
 def assert_islist(ins) -> bool:
+    assert isinstance(ins, list) or isinstance(ins, tuple), _ASSERT_MSG.format(_instance_name_if(ins), "list or tuple")
+
+    return True
+
+
+def assert_islist_strict(ins) -> bool:
     assert isinstance(ins, list), _ASSERT_MSG.format(_instance_name_if(ins), "list")
 
     return True


Test patch:
diff --git a/tests/test_master.py b/tests/test_master.py
index 5691f7b..86e4e64 100644
--- a/tests/test_master.py
+++ b/tests/test_master.py
@@ -289,6 +289,26 @@ class MasterTest(unittest.TestCase):
         for k, exp in expected:
             self.assertIsInstance(ma[k], exp)
 
+    def test_set_db_when_lacked(self):
+        data_p = (("p1", "Taro", 17, "male", "student"),)
+        data_s = (("s1", "stage1"),)
+        data_d = (("d1", "day1"),)
+        data_i = (("i1", "item1"),)
+        data_w = (("w1", "word1"),)
+        data = [
+                (data_p, data_s, data_d, data_i, data_w),
+                (data_p, data_s, data_d, data_i, None),
+                (data_p, data_s, data_d, None, None),
+                (data_p, data_s, None, None, None),
+                (data_p, None, None, None, None),
+                (None, None, None, None, None),
+                ]
+
+        for p, s, d, i, w in data:
+            with self.subTest(p=p, s=s, d=d, i=i, w=w):
+                ma = Master('test')
+                self.assertIsInstance(ma.set_db(p, s, d, i, w), Master)
+
     def test_set_items(self):
         data = (
                 ("t1", "item1"),