Commits

Jonathan Eunice committed 56fc4ce

Added .copy() method and associated tests.

  • Participants
  • Parent commits b29eea6

Comments (0)

Files changed (3)

File options/core.py

             else:
                 self.maps[0][k] = v
                 
-                
+    def copy(self):
+        """
+        Return a copy of the self. That means a copy of just the top layer,
+        with bottom layers showing through.
+        """
+        new = OptionsChain(self.maps[1], {})
+        for k, v in self.items():
+            new[k] = v
+        return new
+  
     # TBD Need to examine all the places we need to check for Prohibited
     # when setting values - eg, what about in Options
     
     # Python needs en passant aliasing.
 
 
-def verno(s):
-    """
-    Update the version number passed in by extending it to the 
-    thousands place and adding 1/1000, then returning that result
-    and as a side-effect updating setup.py
-
-    Dangerous, self-modifying, and also, helps keep version numbers
-    ascending without human intervention.
-    """
-    d = Decimal(s)
-    increment = Decimal('0.001')
-    d = d.quantize(increment) + increment
-    dstr = str(d)
-    setup = open('setup.py', 'r').read()
-    setup = re.sub('verno\(\w*[\'"]([\d\.]+)[\'"]', 'verno("' + dstr + '"', setup)
-    open('setup.py', 'w').write(setup)
-    return dstr
-
 setup(
     name='options',
-    version=verno("0.425"),
+    version=0.45,
     author='Jonathan Eunice',
     author_email='jonathan.eunice@gmail.com',
     description='Container for flexible class, instance, and function call options',

File test/test.py

     
     with pytest.raises(ValueError):
         d = AF('a', 'b', 'c')  # too many values!
-#    
+        
+def test_copy():
+    options = Options(
+            this=1,
+            slick='slack',
+            nick='nack',
+            blik=99,
+            man='man'
+        )
+    o1 = options.copy()
+    assert o1 is not options
+    assert o1 == options
+    o2 = options.push(dict(this=4, blik='rubber'))
+    assert o2.nick == 'nack'
+    assert o2.slick == 'slack'
+    assert o2.blik  == 'rubber'
+    assert o2.this  == 4
+    o3 = o2.copy()
+    assert o3 is not o2
+    assert o3.nick == 'nack'
+    assert o3.slick == 'slack'
+    assert o3.blik  == 'rubber'
+    assert o3.this  == 4
+    o2.slick = 999
+    assert o2.slick == 999
+    assert o3.slick == 'slack'
+ 
 #@pytest.mark.skipif('True')  #under construction
 #def test_write(tmpdir):
 #    o = Options(