Ejemplo n.º 1
0
	def test_filter_items(self):
		# only headings with date and todo should be returned
		tmpdate = date.today()
		odate = OrgDate(True, tmpdate.year, tmpdate.month, tmpdate.day)
		tmp_head = Heading(title=u'Refactor the code', todo=u'TODO', active_date=odate)
		headings = [tmp_head]
		filtered = filter_items(headings,
				[contains_active_date, contains_active_todo])

		self.assertEqual(len(filtered), 1)
		self.assertEqual(filtered, headings)

		# try a longer list
		headings = headings * 3
		filtered = filter_items(headings,
				[contains_active_date, contains_active_todo])

		self.assertEqual(len(filtered), 3)
		self.assertEqual(filtered, headings)

		# date does not contain all needed fields thus gets ignored
		tmpdate = date.today()
		odate = OrgDate(True, tmpdate.year, tmpdate.month, tmpdate.day)
		tmp_head = Heading(title=u'Refactor the code', active_date=odate)
		headings = [tmp_head]
		filtered = filter_items(headings, [contains_active_date,
				contains_active_todo])
		self.assertEqual([], filtered)
Ejemplo n.º 2
0
    def test_heading_parsing_with_date_and_body(self):
        """""
		'text' contains valid dates (in the body).
		"""
        # orgdatetime
        text = [
            "* TODO This is a test <2011-08-25 Thu 10:10> :hallo:",
            "some body text", "some body text"
        ]
        h = Heading.parse_heading_from_data(text, self.allowed_todo_states)
        self.assertTrue(isinstance(h.active_date, OrgDateTime))
        self.assertEqual("<2011-08-25 Thu 10:10>", str(h.active_date))

        text = [
            "* TODO This is a test  :hallo:", "some body text",
            "some body text<2011-08-25 Thu 10:10>"
        ]
        h = Heading.parse_heading_from_data(text, self.allowed_todo_states)
        self.assertTrue(isinstance(h.active_date, OrgDateTime))
        self.assertEqual("<2011-08-25 Thu 10:10>", str(h.active_date))

        text = [
            "* TODO This is a test  :hallo:",
            "some body text <2011-08-24 Wed>",
            "some body text<2011-08-25 Thu 10:10>"
        ]
        h = Heading.parse_heading_from_data(text, self.allowed_todo_states)
        odate = OrgDate(True, 2011, 8, 24)
        self.assertEqual(odate, h.active_date)
Ejemplo n.º 3
0
	def test_contains_active_date(self):
		heading = Heading(title=u'Refactor the code', active_date=None)
		self.assertFalse(contains_active_date(heading))

		odate = OrgDate(True, 2011, 11, 1)
		heading = Heading(title=u'Refactor the code', active_date=odate)
		self.assertTrue(contains_active_date(heading))
Ejemplo n.º 4
0
	def test_is_within_week_with_orgdate(self):
		# to far in the future
		tmpdate = date.today() + timedelta(days=8)
		odate = OrgDate(True, tmpdate.year, tmpdate.month, tmpdate.day)
		heading = Heading(title=u'Refactor the code', active_date=odate)
		self.assertFalse(is_within_week(heading))

		# within a week
		tmpdate = date.today() + timedelta(days=5)
		odate = OrgDate(True, tmpdate.year, tmpdate.month, tmpdate.day)
		heading = Heading(title=u'Refactor the code', active_date=odate)
		self.assertTrue(is_within_week(heading))

		# in the past
		tmpdate = date.today() - timedelta(days=105)
		odate = OrgDate(True, tmpdate.year, tmpdate.month, tmpdate.day)
		heading = Heading(title=u'Refactor the code', active_date=odate)
		self.assertTrue(is_within_week(heading))
Ejemplo n.º 5
0
    def test_filter_items(self):
        # only headings with date and todo should be returned
        vim.command(
            u_encode(
                u"let g:org_todo_keywords = ['TODO', 'STARTED', '|', 'DONE']"))
        tmpdate = date.today()
        odate = OrgDate(True, tmpdate.year, tmpdate.month, tmpdate.day)
        tmp_head = Heading(title=u'Refactor the code',
                           todo=u'TODO',
                           active_date=odate)
        tmp_head_01 = Heading(title=u'Refactor the code',
                              todo=u'STARTED',
                              active_date=odate)
        headings = [tmp_head, tmp_head_01]
        filtered = list(
            filter_items(headings,
                         [contains_active_date, contains_active_todo]))

        self.assertEqual(len(filtered), 2)
        self.assertEqual(filtered, headings)

        # try a longer list
        headings = headings * 3
        filtered = list(
            filter_items(headings,
                         [contains_active_date, contains_active_todo]))

        self.assertEqual(len(filtered), 6)
        self.assertEqual(filtered, headings)

        # date does not contain all needed fields thus gets ignored
        tmpdate = date.today()
        odate = OrgDate(True, tmpdate.year, tmpdate.month, tmpdate.day)
        tmp_head = Heading(title=u'Refactor the code', active_date=odate)
        headings = [tmp_head]
        filtered = list(
            filter_items(headings,
                         [contains_active_date, contains_active_todo]))
        self.assertEqual([], filtered)
Ejemplo n.º 6
0
    def test_heading_parsing_with_date(self):
        """""
		'text' does contain valid dates.
		"""
        # orgdate
        text = ["* TODO This is a test <2011-08-24 Wed> :hallo:"]
        odate = OrgDate(True, 2011, 8, 24)
        h = Heading.parse_heading_from_data(text, self.allowed_todo_states)
        self.assertEqual(odate, h.active_date)

        # orgdatetime
        text = ["* TODO This is a test <2011-08-25 Thu 10:10> :hallo:"]
        odate = OrgDateTime(True, 2011, 8, 25, 10, 10)
        h = Heading.parse_heading_from_data(text, self.allowed_todo_states)
        self.assertEqual(odate, h.active_date)
Ejemplo n.º 7
0
	The function filter_items() can combine different filters and only returns
	the filtered headings.
"""
from datetime import datetime
from datetime import timedelta

try:
    from itertools import ifilter as filter
except:
    pass

# used for putting date to empty "NEXT" agenda
from orgmode.liborgmode.orgdate import OrgDate
today = datetime.today().date()
today = OrgDate(True, today.year, today.month, today.day)


def filter_items(headings, filters):
    u""" Filter the given headings.

	Args:
		headings (list): Contains headings
		filters (list): Filters that will be applied. All functions in
			this module (except this function) are filters.

	Returns:
		filter iterator: Headings which were not filtered.

	Examples:
		>>> filtered = filter_items(headings, [contains_active_date,
Ejemplo n.º 8
0
	def test_OrdDate_str_inactive(self):
		od = OrgDate(False, self.year, self.month, self.day)
		self.assertEqual(self.textinactive, unicode(od))
Ejemplo n.º 9
0
	def test_OrdDate_str_active(self):
		u"""Representation of OrgDates"""
		od = OrgDate(True, self.year, self.month, self.day)
		self.assertEqual(self.text, unicode(od))
Ejemplo n.º 10
0
	def test_OrgDate_ctor_inactive(self):
		u"""OrdDate should be created."""
		today = date.today()
		od = OrgDate(False, today.year, today.month, today.day)
		self.assertTrue(isinstance(od, OrgDate))
		self.assertFalse(od.active)
Ejemplo n.º 11
0
 def test_OrdDate_str_unicode_inactive(self):
     with self.setlocale(self.UTF8_LOCALE):
         od = OrgDate(False, self.year, self.month, self.day)
         self.assertEqual(self.textinactive, unicode(od))