[py-svn] r19754 - in py/branch/traits/py/test: . testing testing/data

jan at codespeak.net jan at codespeak.net
Fri Nov 11 14:16:06 CET 2005


Author: jan
Date: Fri Nov 11 14:16:03 2005
New Revision: 19754

Added:
   py/branch/traits/py/test/testing/data/notraits.py
   py/branch/traits/py/test/testing/data/traits.py
   py/branch/traits/py/test/testing/test_traits.py
Modified:
   py/branch/traits/py/test/collect.py
Log:
every collector has now tags(list) and traits(dict)



Modified: py/branch/traits/py/test/collect.py
==============================================================================
--- py/branch/traits/py/test/collect.py	(original)
+++ py/branch/traits/py/test/collect.py	Fri Nov 11 14:16:03 2005
@@ -215,7 +215,26 @@
     def finishcapture(self): 
         return None # by default collectors don't capture output 
     def getouterr(self): 
-        return self.captured_out, self.captured_err 
+        return self.captured_out, self.captured_err
+
+    def traits(self):
+        def read_traits(traits_list):
+            tags = [tag for tag in traits_list
+                    if isinstance(tag, basestring)]
+            traits = dict([k_v for k_v in traits_list
+                           if isinstance(k_v, tuple)])
+            traits['tags'] = tags
+            return traits
+        
+        if getattr(self, '_traits', None) is None:
+            self._traits = read_traits(getattr(self.obj, 'traits', []))
+        return self._traits
+    traits = property(traits, None, None, "module traits")
+
+    def tags(self):
+        return self.traits['tags']
+    tags =  property(tags, None, None, "module tags")
+    
 
 class FSCollector(Collector): 
     def __init__(self, fspath, parent=None): 
@@ -361,6 +380,7 @@
     Function = property(Function)
 
 class Generator(Collector): 
+    
     def buildname2items(self): 
         d = {} 
         for i, x in py.builtin.enumerate(self.obj()): 

Added: py/branch/traits/py/test/testing/data/notraits.py
==============================================================================
--- (empty file)
+++ py/branch/traits/py/test/testing/data/notraits.py	Fri Nov 11 14:16:03 2005
@@ -0,0 +1,9 @@
+#no traits
+
+class TestNoTraits:
+    # no traits
+    def test_method(self):
+        pass
+
+def test_function(self):
+    pass

Added: py/branch/traits/py/test/testing/data/traits.py
==============================================================================
--- (empty file)
+++ py/branch/traits/py/test/testing/data/traits.py	Fri Nov 11 14:16:03 2005
@@ -0,0 +1,17 @@
+
+traits = ['bob', 'module', ('key', 'value')]
+
+class TestTrait:
+    traits = ['mary', 'class', ('car', 'blue')]
+
+    def test_method(self):
+        pass
+    test_method.traits = ['mary', 'method', ('house', 'green')]
+
+def test_function():
+    pass
+test_function.traits = ['function', ('speed', 'fast')]
+
+def test_generartor(self):
+    yield test_function
+test_generartor.traits= ['generator', ('type', 'flower')]

Added: py/branch/traits/py/test/testing/test_traits.py
==============================================================================
--- (empty file)
+++ py/branch/traits/py/test/testing/test_traits.py	Fri Nov 11 14:16:03 2005
@@ -0,0 +1,88 @@
+from __future__ import generators
+import py
+datadir  = py.magic.autopath().dirpath('data')
+
+class TraitFixture:
+
+    def test_type(self):
+        assert isinstance(self.item, self.type)
+
+    def test_tags(self):
+        assert len(self.tags) == len(self.item.tags)
+        #for x in self.tags:
+        #    assert x in self.item.tags
+        assert self.item.tags == self.tags
+       
+    def test_traits(self):
+         for key,value in self.traits:
+             #if key == 'tags': continue
+             assert self.item.traits[key] == value
+
+    def test_modify_traits(self):
+        # ensure we don't modify a copy
+        self.item.traits['special'] = 'sauce'
+        assert self.item.traits['special'] == 'sauce'
+        self.item.tags.append('dip')
+        assert 'dip' in self.item.traits['tags']
+        assert 'dip' in self.item.tags
+        assert len(self.tags) +1 == len(self.item.tags)
+        
+class TestClass(TraitFixture):
+
+    def setup_method(self, method):
+        col = py.test.collect.Module(datadir.join('traits.py'))
+        l = col.run() 
+        self.item = col.join(l[0])
+        self.type = py.test.collect.Class
+        self.tags = ['mary', 'class']
+        self.traits = [('car', 'blue'), ('tags', self.tags)]
+        
+
+class TestModule(TraitFixture):
+
+    def setup_method(self, method):
+        self.item = py.test.collect.Module(datadir.join('traits.py'))
+        self.type = py.test.collect.Module
+        self.tags = ['bob', 'module']
+        self.traits = [('tags', self.tags), ('key', 'value')]
+
+
+class TestMethod(TraitFixture):
+
+    def setup_method(self, method):
+        col = py.test.collect.Module(datadir.join('traits.py'))
+        l = col.run() 
+        colitem = col.join(l[0])
+        l = colitem.run()
+        instance = colitem.join(l[0])
+        l = instance.run()
+        self.item = instance.join(l[0])
+        self.type = py.test.Function
+        self.tags = ['mary', 'method']
+        self.traits = [('house', 'green'), ('tags', self.tags)]
+
+class TestFunction(TraitFixture):
+
+    def setup_method(self, method):
+        col = py.test.collect.Module(datadir.join('traits.py'))
+        l = col.run() 
+        self.item = col.join(l[1])
+        self.type = py.test.Function
+        self.tags = ['function']
+        self.traits= [('speed','fast'), ('tags', self.tags)]
+
+class TestGenerator(TraitFixture):
+
+    def setup_method(self, method):
+        col = py.test.collect.Module(datadir.join('traits.py'))
+        l = col.run() 
+        self.item = col.join(l[2])
+        self.type = py.test.collect.Generator
+        self.tags = ['generator']
+        self.traits= [('type', 'flower'), ('tags', self.tags)]
+
+
+def test_no_traits_module():
+    col = py.test.collect.Module(datadir.join('notraits.py'))
+    assert len(col.traits) == 1
+    assert col.traits == {'tags':[]} 



More information about the pytest-commit mailing list