Erik Grinaker is sharing code with you
Bitbucket is a code hosting site. Unlimited public and private repositories. Free for small teams.
Don't show this againpython-chrono / tests / test_formatter.py
- Tag
- 0.3.0
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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 | #!/usr/bin/env python
import chrono
import unittest
class Formatter_formatTest(unittest.TestCase):
def setUp(self):
unittest.TestCase.setUp(self)
self.f = chrono.formatter.Formatter(chrono.calendar.ISOCalendar)
def test_012hour(self):
"Formatter.format() handles $012hour"
self.assertEqual(self.f.format(
"$012hour", 2010, 8, 4, 0, 2, 3
), "12")
self.assertEqual(self.f.format(
"$012hour", 2010, 8, 4, 15, 2, 3
), "03")
def test_0day(self):
"Formatter.format() handles $0day"
self.assertEqual(self.f.format(
"$0day", 2010, 8, 4, 1, 2, 3
), "04")
def test_0hour(self):
"Formatter.format() handles $0hour"
self.assertEqual(self.f.format(
"$0hour", 2010, 8, 4, 1, 2, 3
), "01")
def test_0minute(self):
"Formatter.format() handles $0minute"
self.assertEqual(self.f.format(
"$0minute", 2010, 8, 4, 1, 2, 3
), "02")
def test_0month(self):
"Formatter.format() handles $0month"
self.assertEqual(self.f.format(
"$0month", 2010, 8, 4, 1, 2, 3
), "08")
def test_0second(self):
"Formatter.format() handles $0second"
self.assertEqual(self.f.format(
"$0second", 2010, 8, 4, 1, 2, 3
), "03")
def test_0week(self):
"Formatter.format() handles $0week"
self.assertEqual(self.f.format(
"$0week", 2010, 2, 4, 1, 2, 3
), "05")
def test_0year(self):
"Formatter.format() handles $0year"
self.assertEqual(self.f.format(
"$0year", 492, 8, 4, 1, 2, 3
), "0492")
def test_12hour(self):
"Formatter.format() handles $12hour"
self.assertEqual(self.f.format(
"$12hour", 2010, 8, 4, 0, 2, 3
), "12")
self.assertEqual(self.f.format(
"$12hour", 2010, 8, 4, 15, 2, 3
), "3")
def test_ampm(self):
"Formatter.format() handles $ampm"
self.assertEqual(self.f.format(
"$ampm", 2010, 8, 4, 1, 2, 3
), "AM")
self.assertEqual(self.f.format(
"$ampm", 2010, 8, 4, 12, 2, 3
), "PM")
def test_day(self):
"Formatter.format() handles $day"
self.assertEqual(self.f.format(
"$day", 2010, 8, 4, 1, 2, 3
), "4")
def test_escape(self):
"Formatter.format() handles escaped $ signs"
self.assertEqual(self.f.format(
"$year$$$month", 2010, 8, 4, 1, 2, 3
), "2010$8")
def test_hour(self):
"Formatter.format() handles $hour"
self.assertEqual(self.f.format(
"$hour", 2010, 8, 4, 1, 2, 3
), "1")
def test_invalid(self):
"Formatter.format() ignores invalid patterns"
self.assertEqual(self.f.format(
"$-}", 2010, 8, 4, 1, 2, 3
), "$-}")
def test_minute(self):
"Formatter.format() handles $minute"
self.assertEqual(self.f.format(
"$minute", 2010, 8, 4, 1, 2, 3
), "2")
def test_missing(self):
"Formatter.format() returns blank content for variables with no value"
self.assertEqual(self.f.format(
"$0year-$0month-$0day", 2010, None, 4, 1, 2, 3
), "2010--04")
def test_month(self):
"Formatter.format() handles $month"
self.assertEqual(self.f.format(
"$month", 2010, 8, 4, 1, 2, 3
), "8")
def test_monthname(self):
"Formatter.format() handles $monthname"
self.assertEqual(self.f.format(
"$monthname", 2010, 8, 4, 1, 2, 3
), "August")
def test_second(self):
"Formatter.format() handles $second"
self.assertEqual(self.f.format(
"$second", 2010, 8, 4, 1, 2, 3
), "3")
def test_shortmonthname(self):
"Formatter.format() handles $shortmonthname"
self.assertEqual(self.f.format(
"$shortmonthname", 2010, 8, 4, 1, 2, 3
), "Aug")
def test_shortweekdayname(self):
"Formatter.format() handles $shortweekdayname"
self.assertEqual(self.f.format(
"$shortweekdayname", 2010, 8, 4, 1, 2, 3
), "Wed")
def test_shortyear(self):
"Formatter.format() handles $shortyear"
self.assertEqual(self.f.format(
"$shortyear", 2010, 8, 4, 1, 2, 3
), "10")
def test_unknown(self):
"Formatter.format() ignores unknown variables"
self.assertEqual(self.f.format(
"$0year-$dummy-$0day", 2010, 8, 4, 1, 2, 3
), "2010-$dummy-04")
def test_week(self):
"Formatter.format() handles $week"
self.assertEqual(self.f.format(
"$week", 2010, 8, 4, 1, 2, 3
), "31")
def test_weekday(self):
"Formatter.format() handles $weekday"
self.assertEqual(self.f.format(
"$weekday", 2010, 8, 4, 1, 2, 3
), "3")
def test_weekdayname(self):
"Formatter.format() handles $weekdayname"
self.assertEqual(self.f.format(
"$weekdayname", 2010, 8, 4, 1, 2, 3
), "Wednesday")
def test_year(self):
"Formatter.format() handles $year"
self.assertEqual(self.f.format(
"$year", 2010, 8, 4, 1, 2, 3
), "2010")
if __name__ == "__main__":
unittest.main()
|