On Thu, Feb 6, 2014 at 10:11 AM, Jose A. Lopes <[email protected]> wrote:
> If doctests are not being enforced, then we should create an issue in
> the issue list and fix the problem for all docstrings.  But adding a
> comment just to this particular comment is not going to help with
> anything and it is just going to get lost in the middle of the
> codebase.  For sure it is not going to fix the doctests.
>
> So please remove the comment and determine whether the doctests do
> work or not.  If they do not work, then create an issue in the issue
> list.

Enforcing doctests on a module-by-module basis is kind of trivial.
I've gone ahead and added a unit test case that checks the docstrings
(and lo and behold, I had an error in my docstrings).

This is what it looks like:

$ env PYTHONPATH=. ./test/py/ganeti.serializer_unittest.py
Running ganeti.serializer_unittest.py
**********************************************************************
File "/usr/local/google/home/rsanti/ganeti/ganeti/serializer.py", line
233, in ganeti.serializer.Private
Failed example:
    x.upper() == "FOO"
Expected:
    True
Got:
    False
**********************************************************************
1 items had failures:
   1 of   4 in ganeti.serializer.Private
***Test Failed*** 1 failures.
F................
======================================================================
FAIL: testCheckSerializer (__main__.TestCheckDoctests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./test/py/ganeti.serializer_unittest.py", line 222, in
testCheckSerializer
    self.assertEquals(results.failed, 0, "Doctest failures detected")
AssertionError: Doctest failures detected

----------------------------------------------------------------------
Ran 17 tests in 0.013s


 ~ ~ ~

diff --git a/lib/ht.py b/lib/ht.py
index 5f271f9..995889f 100644
--- a/lib/ht.py
+++ b/lib/ht.py
@@ -272,8 +272,10 @@ def TTuple(val):
 def TDict(val):
   """Checks if the given value is a dictionary.

+  Note that L{PrivateDict}s subclass dict and pass this check.
+
   """
-  return isinstance(val, dict) or isinstance(val, PrivateDict)
+  return isinstance(val, dict)


 def TIsLength(size):
diff --git a/lib/serializer.py b/lib/serializer.py
index 3371239..af192be 100644
--- a/lib/serializer.py
+++ b/lib/serializer.py
@@ -300,7 +300,8 @@ class PrivateDict(dict):
     >>> supersekkrit["password"].Get()
     'foobar'
     >>> supersekkrit.GetPrivate("password")
-    'eggspam'
+    'foobar'
+    >>> supersekkrit["user"] = "eggspam"
     >>> supersekkrit.Unprivate()
     {'password': 'foobar', 'user': 'eggspam'}

@@ -348,7 +349,7 @@ class PrivateDict(dict):
       >>> PrivateDict({"foo": "bar"}).GetPrivate("baz", "spam")
       'spam'

-    """ # epydoc does not check doctests, btw.
+    """
     if len(args) == 1:
       key, = args
       return self[key].Get()
diff --git a/test/py/ganeti.serializer_unittest.py
b/test/py/ganeti.serializer_unittest.py
index 20ee4f1..8894c94 100755
--- a/test/py/ganeti.serializer_unittest.py
+++ b/test/py/ganeti.serializer_unittest.py
@@ -23,6 +23,7 @@


 import unittest
+import doctest

 from ganeti import serializer
 from ganeti import errors
@@ -206,12 +207,19 @@ class TestPrivate(unittest.TestCase):

   def testDictGet(self):
     self.assertIs("tar", serializer.PrivateDict().GetPrivate("bar", "tar"),
-                  "Private.GetPrivate() did not handle the default case.")
+                  "Private.GetPrivate() did not handle the default case")

   def testZeronessPrivate(self):
     self.assertTrue(serializer.Private("foo"),
                     "Private of non-empty string is false")
     self.assertFalse(serializer.Private(""), "Private empty string is true")

+
+class TestCheckDoctests(unittest.TestCase):
+
+  def testCheckSerializer(self):
+    results = doctest.testmod(serializer)
+    self.assertEquals(results.failed, 0, "Doctest failures detected")
+
 if __name__ == "__main__":
   testutils.GanetiTestProgram()


-- 
Raffa Santi
Google Germany GmbH
Dienerstr. 12
80331 München


Registergericht und -nummer: Hamburg, HRB 86891
Sitz der Gesellschaft: Hamburg
Geschäftsführer: Graham Law, Christine Elizabeth Flores

Reply via email to