Just for a case of more weirdness, here is my model.py with some extra
doctests thrown in:

import markdown

from django.db import models
from django.forms import ModelForm

import settings

class Flatpage(models.Model):
    """
    >>> 1 + 2
    3
    """
    page_name = models.CharField(max_length=100, primary_key=True,
unique=True)
    title = models.CharField(blank=True, max_length=100)
    description = models.CharField(blank=True, max_length=255)
    markdown_content = models.TextField('content')
    content = models.TextField(editable=False)

    class Meta:
        ordering = ['page_name']

    def __unicode__(self):
        """
        >>> 2 + 3
        5
        """
        return self.page_name

    def get_absolute_url(self):
        """
        >>> 1 + 2
        3

        >>> home_fp = Flatpage.objects.get(page_name="Home")
        >>> home_fp.get_absolute_url()
        '/'

        Test that about page works:
        >>> about_fp = Flatpage.objects.get(page_name="About")
        >>> about_fp.get_absolute_url()
        '/about/'

        Use urlconf to determine url name from page name and then use
url name
        to get absolute url.

        Returns none if there is no url name associated with the page
name.

        Test that homepage works:
        """
        from django.core.urlresolvers import reverse
        from urls import urlpatterns

        for urlpattern in urlpatterns:
            if (hasattr(urlpattern, "default_args") and
                "page" in urlpattern.default_args and
                urlpattern.default_args["page"] == self.page_name and
                hasattr(urlpattern, "name")):

                return reverse(urlpattern.name)

        return None

    def save(self, force_insert=False, force_update=False):
        """
        >>> 1 + 3
        4
        """
        self.content = markdown.markdown(self.markdown_content)
        super(Flatpage, self).save(force_insert, force_update)

and here is the new test output:

Installed 6 object(s) from 1 fixture(s)
Doctest: osl_flatpages.models.Flatpage ... ok
Doctest: osl_flatpages.models.Flatpage.__unicode__ ... ok
Doctest: osl_flatpages.models.Flatpage.save ... ok

----------------------------------------------------------------------
Ran 3 tests in 0.005s

It appears to be running doctests for every method except for
get_absolute_url.


On Jul 10, 11:45 pm, Jeff <jeffreychar...@gmail.com> wrote:
> Just to follow-up, the syntax itself does not appear to be a problem:
>
> >>> import doctest
> >>> import osl_flatpages
> >>> doctest.testmod(osl_flatpages.models, verbose=1)
>
> Trying:
>     home_fp = Flatpage.objects.get(page_name="Home")
> Expecting nothing
> ok
> Trying:
>     home_fp.get_absolute_url()
> Expecting:
>     '/'
> ok
> Trying:
>     about_fp = Flatpage.objects.get(page_name="About")
> Expecting nothing
> ok
> Trying:
>     about_fp.get_absolute_url()
> Expecting:
>     '/about/'
> ok
> 6 items had no tests:
>     osl_flatpages.models
>     osl_flatpages.models.Flatpage
>     osl_flatpages.models.Flatpage.DoesNotExist
>     osl_flatpages.models.Flatpage.MultipleObjectsReturned
>     osl_flatpages.models.Flatpage.__unicode__
>     osl_flatpages.models.Flatpage.save
> 1 items passed all tests:
>    4 tests in osl_flatpages.models.Flatpage.get_absolute_url
> 4 tests in 7 items.
> 4 passed and 0 failed.
> Test passed.
> TestResults(failed=0, attempted=4)
>
> So the problem appears to be with the Django test runner not adding
> the doctests to the test suite it runs. I'm still not sure how to fix
> this issue unfortunately.
>
> On Jul 10, 9:50 pm, Jeff <jeffreychar...@gmail.com> wrote:
>
>
>
> > Hi,
>
> > I have a rather complicated get_absolute_url method in a models.py
> > file that I wanted to use two doctests to check. Unfortunately the
> > doctests do not appear to run when I run python manage.py test
> > according to the verbose output.
>
> > Here is the method:
>
> >     def get_absolute_url(self):
> >         """
> >         Use urlconf to determine url name from page name and then use
> > url name
> >         to get absolute url.
>
> >         Returns none if there is no url name associated with the page
> > name.
>
> >         Test that homepage works:
> >         >>> home_fp = Flatpage.objects.get(page_name="Home")
> >         >>> home_fp.get_absolute_url()
> >         '/'
>
> >         Test that about page works:
> >         >>> about_fp = Flatpage.objects.get(page_name="About")
> >         >>> about_fp.get_absolute_url()
> >         '/about/'
> >         """
> >         from django.core.urlresolvers import reverse
> >         from urls import urlpatterns
>
> >         for urlpattern in urlpatterns:
> >             if (hasattr(urlpattern, "default_args") and
> >                 "page" in urlpattern.default_args and
> >                 urlpattern.default_args["page"] == self.page_name and
> >                 hasattr(urlpattern, "name")):
>
> >                 return reverse(urlpattern.name)
>
> >         return None
>
> > And here is the test output:
> > Installed 6 object(s) from 1 fixture(s)
> > test_correct_template_loaded
> > (osl_flatpages.tests.views.OslFlatpageTestCase) ... ok
> > test_description (osl_flatpages.tests.views.OslFlatpageTestCase) ...
> > ok
> > test_existent (osl_flatpages.tests.views.OslFlatpageTestCase) ... ok
> > test_nonexistent (osl_flatpages.tests.views.OslFlatpageTestCase) ...
> > ok
> > test_nontemplate_content
> > (osl_flatpages.tests.views.OslFlatpageTestCase) ... ok
> > test_template_content
> > (osl_flatpages.tests.views.OslFlatpageTestCase) ... ok
> > test_title (osl_flatpages.tests.views.OslFlatpageTestCase) ... ok
>
> > ----------------------------------------------------------------------
> > Ran 7 tests in 0.415s
>
> > As you can see, there is no mention of the two doctests being run.
>
> > Any ideas as to why the two doctests are not running?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to