Source

options / test / test.py

Diff from to

File test/test.py

 
 from options import *
-import sys
-import six
+import sys, six, pytest
     
 def test_good_chainstuf():
     """Test options class for being faithful subclass of chainstuf"""
     assert t.options.man == 'BOY'
     t.set(man='girl')
     assert t.options.man == 'GIRL'
-    
-
    
 def test_push():
     
     assert ooo.a is f1
     assert ooo.b is f3
     assert ooo.c == 12
+    
+def test_addflat():
+    class AF(object):
+        options = Options(
+            prefix = None,
+            suffix = None
+        )
+        
+        def __init__(self, *args, **kwargs):
+            self.options = AF.options.push(kwargs)
+            if args:
+                used = self.options.addflat(args, ['prefix', 'suffix'])
+                if 'suffix' not in used:
+                    self.options.suffix = self.options.prefix
+    
+    a = AF(prefix='[', suffix=']')
+    assert a.options.prefix == '['
+    assert a.options.suffix == ']'
+    
+    b = AF('|')
+    assert b.options.prefix == '|' == b.options.suffix
+    
+    c = AF('{', '}')
+    assert c.options.prefix == '{'
+    assert c.options.suffix == '}'
+    
+    with pytest.raises(ValueError):
+        d = AF('a', 'b', 'c')  # too many values!
+    
+