Repository: medialab/casanova

Issue:
namedrecord plural fields should accept arbitrary iterables

Discussion:

Patch:
diff --git a/casanova/namedrecord.py b/casanova/namedrecord.py
index 7a1157f..bbe16e2 100644
--- a/casanova/namedrecord.py
+++ b/casanova/namedrecord.py
@@ -6,6 +6,7 @@
 #
 from json import dumps
 from collections import OrderedDict
+from collections.abc import Iterable
 
 from casanova._namedtuple import future_namedtuple
 
@@ -37,7 +38,7 @@ def namedrecord(name, fields, boolean=None, plural=None, json=None, defaults=Non
             return 'true' if v else 'false'
 
         if m == 2:
-            assert isinstance(v, list)
+            assert isinstance(v, Iterable)
             return plural_separator.join(str(i) for i in v)
 
         if m == 3:


Test patch:
diff --git a/test/namedrecord_test.py b/test/namedrecord_test.py
index fdcd728..5c58f90 100644
--- a/test/namedrecord_test.py
+++ b/test/namedrecord_test.py
@@ -84,3 +84,23 @@ class TestNamedRecord(object):
         r = Record('Test', None)
 
         assert r.as_csv_row() == ['Test', None]
+
+    def test_set_is_plural(self):
+
+        Video = namedrecord(
+            'Video',
+            ['title', 'has_captions', 'tags'],
+            boolean=['has_captions'],
+            plural=['tags']
+        )
+
+        v = Video('Super video', True, {'film', 'pop'})
+
+        assert v.as_csv_row() == ['Super video', 'true', 'film|pop'] or v.as_csv_row() == ['Super video', 'true', 'pop|film']
+        assert v.as_dict() == {
+            'title': 'Super video',
+            'has_captions': True,
+            'tags': {'film', 'pop'}
+        }
+
+        assert Video.fieldnames == ['title', 'has_captions', 'tags']