-
Notifications
You must be signed in to change notification settings - Fork 268
/
Copy pathtest_libheading.py
154 lines (119 loc) · 5.95 KB
/
test_libheading.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# -*- coding: utf-8 -*-
import unittest
import sys
sys.path.append(u'../ftplugin')
from orgmode.liborgmode.headings import Heading
from orgmode.liborgmode.orgdate import OrgDate
from orgmode.liborgmode.orgdate import OrgDateTime
class TestHeadingRecognizeDatesInHeading(unittest.TestCase):
def setUp(self):
self.allowed_todo_states = ["TODO"]
tmp = ["* This heading is earlier <2011-08-24 Wed>"]
self.h1 = Heading.parse_heading_from_data(tmp, self.allowed_todo_states)
tmp = ["* This heading is later <2011-08-25 Thu>"]
self.h2 = Heading.parse_heading_from_data(tmp, self.allowed_todo_states)
tmp = ["* This heading is later <2011-08-25 Thu 10:20>"]
self.h2_datetime = Heading.parse_heading_from_data(tmp, self.allowed_todo_states)
tmp = ["* This heading is later <2011-08-26 Fri 10:20>"]
self.h3 = Heading.parse_heading_from_data(tmp, self.allowed_todo_states)
tmp = ["* This heading has no date and should be later than the rest"]
self.h_no_date = Heading.parse_heading_from_data(tmp,
self.allowed_todo_states)
def test_heading_parsing_no_date(self):
"""""
'text' doesn't contain any valid date.
"""
text = ["* TODO This is a test :hallo:"]
h = Heading.parse_heading_from_data(text, self.allowed_todo_states)
self.assertEqual(None, h.active_date)
text = ["* TODO This is a test <2011-08-25>"]
h = Heading.parse_heading_from_data(text, self.allowed_todo_states)
self.assertEqual(None, h.active_date)
text = ["* TODO This is a test <2011-08-25 Wednesday>"]
h = Heading.parse_heading_from_data(text, self.allowed_todo_states)
self.assertEqual(None, h.active_date)
text = ["* TODO This is a test <20110825>"]
h = Heading.parse_heading_from_data(text, self.allowed_todo_states)
self.assertEqual(None, h.active_date)
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)
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)
def test_less_than_for_dates_in_heading(self):
self.assertTrue(self.h1 < self.h2)
self.assertTrue(self.h1 < self.h3)
self.assertTrue(self.h1 < self.h_no_date)
self.assertTrue(self.h2 < self.h_no_date)
self.assertTrue(self.h2 < self.h3)
self.assertTrue(self.h3 < self.h_no_date)
self.assertFalse(self.h2 < self.h1)
self.assertFalse(self.h3 < self.h2)
def test_less_equal_for_dates_in_heading(self):
self.assertTrue(self.h1 <= self.h2)
self.assertTrue(self.h1 <= self.h_no_date)
self.assertTrue(self.h2 <= self.h_no_date)
self.assertTrue(self.h2 <= self.h2_datetime)
self.assertTrue(self.h2 <= self.h3)
def test_greate_than_for_dates_in_heading(self):
self.assertTrue(self.h2 > self.h1)
self.assertTrue(self.h_no_date > self.h1)
self.assertTrue(self.h_no_date > self.h2)
self.assertFalse(self.h2 > self.h2_datetime)
def test_greate_equal_for_dates_in_heading(self):
self.assertTrue(self.h2 >= self.h1)
self.assertTrue(self.h_no_date >= self.h1)
self.assertTrue(self.h_no_date >= self.h2)
self.assertTrue(self.h2 >= self.h2_datetime)
def test_sorting_of_headings(self):
"""Headings should be sortable."""
self.assertEqual([self.h1, self.h2], sorted([self.h2, self.h1]))
self.assertEqual([self.h1, self.h2_datetime],
sorted([self.h2_datetime, self.h1]))
self.assertEqual([self.h2_datetime, self.h2],
sorted([self.h2_datetime, self.h2]))
self.assertEqual([self.h1, self.h2], sorted([self.h1, self.h2]))
self.assertEqual([self.h1, self.h_no_date],
sorted([self.h1, self.h_no_date]))
self.assertEqual([self.h1, self.h_no_date],
sorted([self.h_no_date, self.h1]))
self.assertEqual([self.h1, self.h2, self.h_no_date],
sorted([self.h2, self.h_no_date, self.h1]))
self.assertEqual(
[self.h1, self.h2_datetime, self.h2, self.h3, self.h_no_date],
sorted([self.h2_datetime, self.h3, self.h2, self.h_no_date, self.h1]))
def suite():
return unittest.TestLoader().loadTestsFromTestCase(
TestHeadingRecognizeDatesInHeading)