<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[15020] PyCalendar/trunk/src/pycalendar/icalendar</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/15020">15020</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2015-07-31 19:37:47 -0700 (Fri, 31 Jul 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Fix issue with monthly,byday/bysetpos rrule expansion. Re-factor tests to make it easier to add new rules for testing. Fix a source file encoding issue.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#PyCalendartrunksrcpycalendaricalendarrecurrencepy">PyCalendar/trunk/src/pycalendar/icalendar/recurrence.py</a></li>
<li><a href="#PyCalendartrunksrcpycalendaricalendarteststest_jsonpy">PyCalendar/trunk/src/pycalendar/icalendar/tests/test_json.py</a></li>
<li><a href="#PyCalendartrunksrcpycalendaricalendarteststest_recurrencepy">PyCalendar/trunk/src/pycalendar/icalendar/tests/test_recurrence.py</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#PyCalendartrunksrcpycalendaricalendartestsrrule_examplesjson">PyCalendar/trunk/src/pycalendar/icalendar/tests/rrule_examples.json</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="PyCalendartrunksrcpycalendaricalendarrecurrencepy"></a>
<div class="modfile"><h4>Modified: PyCalendar/trunk/src/pycalendar/icalendar/recurrence.py (15019 => 15020)</h4>
<pre class="diff"><span>
<span class="info">--- PyCalendar/trunk/src/pycalendar/icalendar/recurrence.py        2015-07-31 19:11:05 UTC (rev 15019)
+++ PyCalendar/trunk/src/pycalendar/icalendar/recurrence.py        2015-08-01 02:37:47 UTC (rev 15020)
</span><span class="lines">@@ -1007,9 +1007,6 @@
</span><span class="cx">             elif self.mFreq == definitions.eRecurrence_YEARLY:
</span><span class="cx">                 self.generateYearlySet(start_iter, set_items)
</span><span class="cx"> 
</span><del>-            # Ignore if it is invalid
-            set_items = filter(lambda x: not x.invalid(), set_items)
-
</del><span class="cx">             # Always sort the set as BYxxx rules may not be sorted
</span><span class="cx">             # set_items.sort(cmp=DateTime.sort)
</span><span class="cx">             set_items.sort(key=lambda x: x.getPosixTime())
</span><span class="lines">@@ -1143,6 +1140,9 @@
</span><span class="cx">         if (self.mBySeconds is not None) and (len(self.mBySeconds) != 0):
</span><span class="cx">             items[:] = self.bySecondExpand(items)
</span><span class="cx"> 
</span><ins>+        # Remove invalid items before BYSETPOS
+        items[:] = filter(lambda x: not x.invalid(), items)
+
</ins><span class="cx">         if (self.mBySetPos is not None) and (len(self.mBySetPos) != 0):
</span><span class="cx">             items[:] = self.bySetPosLimit(items)
</span><span class="cx"> 
</span><span class="lines">@@ -1188,6 +1188,9 @@
</span><span class="cx">         if ((self.mBySeconds is not None) and (len(self.mBySeconds) != 0)):
</span><span class="cx">             items[:] = self.bySecondExpand(items)
</span><span class="cx"> 
</span><ins>+        # Remove invalid items before BYSETPOS
+        items[:] = filter(lambda x: not x.invalid(), items)
+
</ins><span class="cx">         if ((self.mBySetPos is not None) and (len(self.mBySetPos) != 0)):
</span><span class="cx">             items[:] = self.bySetPosLimit(items)
</span><span class="cx"> 
</span><span class="lines">@@ -1225,6 +1228,9 @@
</span><span class="cx">         if (self.mBySeconds is not None) and (len(self.mBySeconds) != 0):
</span><span class="cx">             items[:] = self.bySecondExpand(items)
</span><span class="cx"> 
</span><ins>+        # Remove invalid items before BYSETPOS
+        items[:] = filter(lambda x: not x.invalid(), items)
+
</ins><span class="cx">         if (self.mBySetPos is not None) and (len(self.mBySetPos) != 0):
</span><span class="cx">             items[:] = self.bySetPosLimit(items)
</span><span class="cx"> 
</span><span class="lines">@@ -1267,6 +1273,9 @@
</span><span class="cx">         if (self.mBySeconds is not None) and (len(self.mBySeconds) != 0):
</span><span class="cx">             items[:] = self.bySecondExpand(items)
</span><span class="cx"> 
</span><ins>+        # Remove invalid items before BYSETPOS
+        items[:] = filter(lambda x: not x.invalid(), items)
+
</ins><span class="cx">         if (self.mBySetPos is not None) and (len(self.mBySetPos) != 0):
</span><span class="cx">             items[:] = self.bySetPosLimit(items)
</span><span class="cx"> 
</span><span class="lines">@@ -1311,6 +1320,9 @@
</span><span class="cx">         if (self.mBySeconds is not None) and (len(self.mBySeconds) != 0):
</span><span class="cx">             items[:] = self.bySecondExpand(items)
</span><span class="cx"> 
</span><ins>+        # Remove invalid items before BYSETPOS
+        items[:] = filter(lambda x: not x.invalid(), items)
+
</ins><span class="cx">         if (self.mBySetPos is not None) and (len(self.mBySetPos) != 0):
</span><span class="cx">             items[:] = self.bySetPosLimit(items)
</span><span class="cx"> 
</span><span class="lines">@@ -1357,6 +1369,9 @@
</span><span class="cx">         if (self.mBySeconds is not None) and (len(self.mBySeconds) != 0):
</span><span class="cx">             items[:] = self.bySecondExpand(items)
</span><span class="cx"> 
</span><ins>+        # Remove invalid items before BYSETPOS
+        items[:] = filter(lambda x: not x.invalid(), items)
+
</ins><span class="cx">         if (self.mBySetPos is not None) and (len(self.mBySetPos) != 0):
</span><span class="cx">             items[:] = self.bySetPosLimit(items)
</span><span class="cx"> 
</span><span class="lines">@@ -1405,6 +1420,9 @@
</span><span class="cx">             if (len(items) == 0):
</span><span class="cx">                 return
</span><span class="cx"> 
</span><ins>+        # Remove invalid items before BYSETPOS
+        items[:] = filter(lambda x: not x.invalid(), items)
+
</ins><span class="cx">         if (self.mBySetPos is not None) and (len(self.mBySetPos) != 0):
</span><span class="cx">             items[:] = self.bySetPosLimit(items)
</span><span class="cx"> 
</span></span></pre></div>
<a id="PyCalendartrunksrcpycalendaricalendartestsrrule_examplesjson"></a>
<div class="addfile"><h4>Added: PyCalendar/trunk/src/pycalendar/icalendar/tests/rrule_examples.json (0 => 15020)</h4>
<pre class="diff"><span>
<span class="info">--- PyCalendar/trunk/src/pycalendar/icalendar/tests/rrule_examples.json                                (rev 0)
+++ PyCalendar/trunk/src/pycalendar/icalendar/tests/rrule_examples.json        2015-08-01 02:37:47 UTC (rev 15020)
</span><span class="lines">@@ -0,0 +1,231 @@
</span><ins>+[
+        {
+                &quot;rule&quot;: &quot;FREQ=YEARLY;BYWEEKNO=1,2&quot;,
+                &quot;start&quot;: &quot;20130101T000000&quot;,
+                &quot;end&quot;: &quot;20170101T000000&quot;,
+                &quot;results&quot;: [
+            &quot;20130101T000000&quot;,
+            &quot;20130108T000000&quot;,
+            &quot;20140101T000000&quot;,
+            &quot;20140108T000000&quot;,
+            &quot;20150101T000000&quot;,
+            &quot;20150108T000000&quot;,
+            &quot;20160108T000000&quot;,
+            &quot;20160115T000000&quot;
+                ]
+        },
+        {
+                &quot;rule&quot;: &quot;FREQ=MONTHLY&quot;,
+                &quot;start&quot;: &quot;20140140T120000&quot;,
+                &quot;end&quot;: &quot;20150101T000000&quot;,
+                &quot;results&quot;: [
+            &quot;20140209T120000&quot;,
+            &quot;20140309T120000&quot;,
+            &quot;20140409T120000&quot;,
+            &quot;20140509T120000&quot;,
+            &quot;20140609T120000&quot;,
+            &quot;20140709T120000&quot;,
+            &quot;20140809T120000&quot;,
+            &quot;20140909T120000&quot;,
+            &quot;20141009T120000&quot;,
+            &quot;20141109T120000&quot;,
+            &quot;20141209T120000&quot;
+                ]
+        },
+        {
+                &quot;rule&quot;: &quot;FREQ=MONTHLY&quot;,
+                &quot;start&quot;: &quot;20140131T120000&quot;,
+                &quot;end&quot;: &quot;20150101T000000&quot;,
+                &quot;results&quot;: [
+                        &quot;20140131T120000&quot;,
+                        &quot;20140331T120000&quot;,
+                        &quot;20140531T120000&quot;,
+                        &quot;20140731T120000&quot;,
+                        &quot;20140831T120000&quot;,
+                        &quot;20141031T120000&quot;,
+                        &quot;20141231T120000&quot;
+                ]
+        },
+        {
+                &quot;rule&quot;: &quot;FREQ=MONTHLY;BYMONTHDAY=31&quot;,
+                &quot;start&quot;: &quot;20140131T120000&quot;,
+                &quot;end&quot;: &quot;20150101T000000&quot;,
+                &quot;results&quot;: [
+                        &quot;20140131T120000&quot;,
+                        &quot;20140331T120000&quot;,
+                        &quot;20140531T120000&quot;,
+                        &quot;20140731T120000&quot;,
+                        &quot;20140831T120000&quot;,
+                        &quot;20141031T120000&quot;,
+                        &quot;20141231T120000&quot;
+                ]
+        },
+        {
+                &quot;rule&quot;: &quot;FREQ=MONTHLY;BYMONTHDAY=-31&quot;,
+                &quot;start&quot;: &quot;20140101T120000&quot;,
+                &quot;end&quot;: &quot;20150101T000000&quot;,
+                &quot;results&quot;: [
+                        &quot;20140101T120000&quot;,
+                        &quot;20140301T120000&quot;,
+                        &quot;20140501T120000&quot;,
+                        &quot;20140701T120000&quot;,
+                        &quot;20140801T120000&quot;,
+                        &quot;20141001T120000&quot;,
+                        &quot;20141201T120000&quot;
+                ]
+        },
+        {
+                &quot;rule&quot;: &quot;FREQ=MONTHLY;BYDAY=-1FR&quot;,
+                &quot;start&quot;: &quot;20140131T120000&quot;,
+                &quot;end&quot;: &quot;20150101T000000&quot;,
+                &quot;results&quot;: [
+                        &quot;20140131T120000&quot;,
+                        &quot;20140228T120000&quot;,
+                        &quot;20140328T120000&quot;,
+                        &quot;20140425T120000&quot;,
+                        &quot;20140530T120000&quot;,
+                        &quot;20140627T120000&quot;,
+                        &quot;20140725T120000&quot;,
+                        &quot;20140829T120000&quot;,
+                        &quot;20140926T120000&quot;,
+                        &quot;20141031T120000&quot;,
+                        &quot;20141128T120000&quot;,
+                        &quot;20141226T120000&quot;
+                ]
+        },
+        {
+                &quot;rule&quot;: &quot;FREQ=MONTHLY;BYDAY=5FR&quot;,
+                &quot;start&quot;: &quot;20140131T120000&quot;,
+                &quot;end&quot;: &quot;20150101T000000&quot;,
+                &quot;results&quot;: [
+                        &quot;20140131T120000&quot;,
+                        &quot;20140530T120000&quot;,
+                        &quot;20140829T120000&quot;,
+                        &quot;20141031T120000&quot;
+                ]
+        },
+        {
+                &quot;rule&quot;: &quot;FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1&quot;,
+                &quot;start&quot;: &quot;20140131T120000&quot;,
+                &quot;end&quot;: &quot;20150101T000000&quot;,
+                &quot;results&quot;: [
+                        &quot;20140131T120000&quot;,
+                        &quot;20140228T120000&quot;,
+                        &quot;20140331T120000&quot;,
+                        &quot;20140430T120000&quot;,
+                        &quot;20140530T120000&quot;,
+                        &quot;20140630T120000&quot;,
+                        &quot;20140731T120000&quot;,
+                        &quot;20140829T120000&quot;,
+                        &quot;20140930T120000&quot;,
+                        &quot;20141031T120000&quot;,
+                        &quot;20141128T120000&quot;,
+                        &quot;20141231T120000&quot;
+                ]
+        },
+        {
+                &quot;rule&quot;: &quot;FREQ=MONTHLY;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1&quot;,
+                &quot;start&quot;: &quot;20140127T120000&quot;,
+                &quot;end&quot;: &quot;20150101T000000&quot;,
+                &quot;results&quot;: [
+                        &quot;20140131T120000&quot;,
+                        &quot;20140228T120000&quot;,
+                        &quot;20140331T120000&quot;,
+                        &quot;20140430T120000&quot;,
+                        &quot;20140530T120000&quot;,
+                        &quot;20140630T120000&quot;,
+                        &quot;20140731T120000&quot;,
+                        &quot;20140829T120000&quot;,
+                        &quot;20140930T120000&quot;,
+                        &quot;20141031T120000&quot;,
+                        &quot;20141128T120000&quot;,
+                        &quot;20141231T120000&quot;
+                ]
+        },
+        {
+                &quot;rule&quot;: &quot;FREQ=MONTHLY;INTERVAL=2;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=-1&quot;,
+                &quot;start&quot;: &quot;20140127T120000&quot;,
+                &quot;end&quot;: &quot;20150101T000000&quot;,
+                &quot;results&quot;: [
+                        &quot;20140131T120000&quot;,
+                        &quot;20140331T120000&quot;,
+                        &quot;20140530T120000&quot;,
+                        &quot;20140731T120000&quot;,
+                        &quot;20140930T120000&quot;,
+                        &quot;20141128T120000&quot;
+                ]
+        },
+        {
+                &quot;rule&quot;: &quot;FREQ=MONTHLY;BYDAY=-1MO,-1TU,-1WE,-1TH,-1FR;BYSETPOS=-1&quot;,
+                &quot;start&quot;: &quot;20140130T120000&quot;,
+                &quot;end&quot;: &quot;20150101T000000&quot;,
+                &quot;results&quot;: [
+                        &quot;20140131T120000&quot;,
+                        &quot;20140228T120000&quot;,
+                        &quot;20140331T120000&quot;,
+                        &quot;20140430T120000&quot;,
+                        &quot;20140530T120000&quot;,
+                        &quot;20140630T120000&quot;,
+                        &quot;20140731T120000&quot;,
+                        &quot;20140829T120000&quot;,
+                        &quot;20140930T120000&quot;,
+                        &quot;20141031T120000&quot;,
+                        &quot;20141128T120000&quot;,
+                        &quot;20141231T120000&quot;
+                ]
+        },
+        {
+                &quot;rule&quot;: &quot;FREQ=YEARLY&quot;,
+                &quot;start&quot;: &quot;20120229T120000&quot;,
+                &quot;end&quot;: &quot;20200101T000000&quot;,
+                &quot;results&quot;: [
+                        &quot;20120229T120000&quot;,
+                        &quot;20160229T120000&quot;
+                ]
+        },
+        {
+                &quot;rule&quot;: &quot;FREQ=YEARLY;BYYEARDAY=366&quot;,
+                &quot;start&quot;: &quot;20121231T120000&quot;,
+                &quot;end&quot;: &quot;20200101T000000&quot;,
+                &quot;results&quot;: [
+                        &quot;20121231T120000&quot;,
+                        &quot;20161231T120000&quot;
+                ]
+        },
+        {
+                &quot;rule&quot;: &quot;FREQ=YEARLY;BYDAY=-1FR;BYMONTH=10&quot;,
+                &quot;start&quot;: &quot;20101029T120000&quot;,
+                &quot;end&quot;: &quot;20150101T000000&quot;,
+                &quot;results&quot;: [
+                        &quot;20101029T120000&quot;,
+                        &quot;20111028T120000&quot;,
+                        &quot;20121026T120000&quot;,
+                        &quot;20131025T120000&quot;,
+                        &quot;20141031T120000&quot;
+                ]
+        },
+        {
+                &quot;rule&quot;: &quot;FREQ=YEARLY;BYDAY=1FR;BYMONTH=4&quot;,
+                &quot;start&quot;: &quot;20100402T120000&quot;,
+                &quot;end&quot;: &quot;20150101T000000&quot;,
+                &quot;results&quot;: [
+                        &quot;20100402T120000&quot;,
+                        &quot;20110401T120000&quot;,
+                        &quot;20120406T120000&quot;,
+                        &quot;20130405T120000&quot;,
+                        &quot;20140404T120000&quot;
+                ]
+        },
+        {
+                &quot;rule&quot;: &quot;FREQ=YEARLY;BYDAY=FR;BYMONTHDAY=21,22,23,24,25,26,27;BYMONTH=10&quot;,
+                &quot;start&quot;: &quot;20101022T120000&quot;,
+                &quot;end&quot;: &quot;20150101T000000&quot;,
+                &quot;results&quot;: [
+                        &quot;20101022T120000&quot;,
+                        &quot;20111021T120000&quot;,
+                        &quot;20121026T120000&quot;,
+                        &quot;20131025T120000&quot;,
+                        &quot;20141024T120000&quot;
+                ]
+        }
+]
</ins></span></pre></div>
<a id="PyCalendartrunksrcpycalendaricalendarteststest_jsonpy"></a>
<div class="modfile"><h4>Modified: PyCalendar/trunk/src/pycalendar/icalendar/tests/test_json.py (15019 => 15020)</h4>
<pre class="diff"><span>
<span class="info">--- PyCalendar/trunk/src/pycalendar/icalendar/tests/test_json.py        2015-07-31 19:11:05 UTC (rev 15019)
+++ PyCalendar/trunk/src/pycalendar/icalendar/tests/test_json.py        2015-08-01 02:37:47 UTC (rev 15020)
</span><span class="lines">@@ -1,3 +1,4 @@
</span><ins>+# -*- coding: utf-8 -*-
</ins><span class="cx"> ##
</span><span class="cx"> #    Copyright (c) 2007-2013 Cyrus Daboo. All rights reserved.
</span><span class="cx"> #
</span><span class="lines">@@ -14,6 +15,7 @@
</span><span class="cx"> #    limitations under the License.
</span><span class="cx"> ##
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> from pycalendar.icalendar.calendar import Calendar
</span><span class="cx"> from pycalendar.icalendar.property import Property
</span><span class="cx"> import difflib
</span></span></pre></div>
<a id="PyCalendartrunksrcpycalendaricalendarteststest_recurrencepy"></a>
<div class="modfile"><h4>Modified: PyCalendar/trunk/src/pycalendar/icalendar/tests/test_recurrence.py (15019 => 15020)</h4>
<pre class="diff"><span>
<span class="info">--- PyCalendar/trunk/src/pycalendar/icalendar/tests/test_recurrence.py        2015-07-31 19:11:05 UTC (rev 15019)
+++ PyCalendar/trunk/src/pycalendar/icalendar/tests/test_recurrence.py        2015-08-01 02:37:47 UTC (rev 15020)
</span><span class="lines">@@ -19,6 +19,8 @@
</span><span class="cx"> from pycalendar.icalendar.recurrence import Recurrence
</span><span class="cx"> import unittest
</span><span class="cx"> from pycalendar.timezone import Timezone
</span><ins>+import os
+import json
</ins><span class="cx"> 
</span><span class="cx"> class TestRecurrence(unittest.TestCase):
</span><span class="cx"> 
</span><span class="lines">@@ -116,57 +118,6 @@
</span><span class="cx">             self.assertNotEqual(hashes[i - 1], hashes[i])
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def testByWeekNoExpand(self):
-
-        recur = Recurrence()
-        recur.parse(&quot;FREQ=YEARLY;BYWEEKNO=1,2&quot;)
-        start = DateTime(2013, 1, 1, 0, 0, 0)
-        end = DateTime(2017, 1, 1, 0, 0, 0)
-        items = []
-        range = Period(start, end)
-        recur.expand(start, range, items)
-        self.assertEqual(
-            items,
-            [
-                DateTime(2013, 1, 1, 0, 0, 0),
-                DateTime(2013, 1, 8, 0, 0, 0),
-                DateTime(2014, 1, 1, 0, 0, 0),
-                DateTime(2014, 1, 8, 0, 0, 0),
-                DateTime(2015, 1, 1, 0, 0, 0),
-                DateTime(2015, 1, 8, 0, 0, 0),
-                DateTime(2016, 1, 8, 0, 0, 0),
-                DateTime(2016, 1, 15, 0, 0, 0),
-            ],
-        )
-
-
-    def testMonthlyInvalidStart(self):
-
-        recur = Recurrence()
-        recur.parse(&quot;FREQ=MONTHLY&quot;)
-        start = DateTime(2014, 1, 40, 12, 0, 0)
-        end = DateTime(2015, 1, 1, 0, 0, 0)
-        items = []
-        range = Period(start, end)
-        recur.expand(start, range, items)
-        self.assertEqual(
-            items,
-            [
-                DateTime(2014, 2, 9, 12, 0, 0),
-                DateTime(2014, 3, 9, 12, 0, 0),
-                DateTime(2014, 4, 9, 12, 0, 0),
-                DateTime(2014, 5, 9, 12, 0, 0),
-                DateTime(2014, 6, 9, 12, 0, 0),
-                DateTime(2014, 7, 9, 12, 0, 0),
-                DateTime(2014, 8, 9, 12, 0, 0),
-                DateTime(2014, 9, 9, 12, 0, 0),
-                DateTime(2014, 10, 9, 12, 0, 0),
-                DateTime(2014, 11, 9, 12, 0, 0),
-                DateTime(2014, 12, 9, 12, 0, 0),
-            ],
-        )
-
-
</del><span class="cx">     def testWeeklyTwice(self):
</span><span class="cx"> 
</span><span class="cx">         recur = Recurrence()
</span><span class="lines">@@ -230,166 +181,37 @@
</span><span class="cx">                 DateTime(2014, 7, 1, 12, 0, 0, tzid=Timezone(tzid=&quot;America/New_York&quot;)),
</span><span class="cx">                 DateTime(2014, 8, 1, 12, 0, 0, tzid=Timezone(tzid=&quot;America/New_York&quot;)),
</span><span class="cx">                 DateTime(2014, 9, 1, 12, 0, 0, tzid=Timezone(tzid=&quot;America/New_York&quot;)),
</span><del>-                DateTime(2014, 10, 1, 12, 0, 0),
-                DateTime(2014, 11, 1, 12, 0, 0),
-                DateTime(2014, 12, 1, 12, 0, 0),
</del><ins>+                DateTime(2014, 10, 1, 12, 0, 0, tzid=Timezone(tzid=&quot;America/New_York&quot;)),
+                DateTime(2014, 11, 1, 12, 0, 0, tzid=Timezone(tzid=&quot;America/New_York&quot;)),
+                DateTime(2014, 12, 1, 12, 0, 0, tzid=Timezone(tzid=&quot;America/New_York&quot;)),
</ins><span class="cx">             ],
</span><span class="cx">         )
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def testMonthlyStart31st(self):
</del><ins>+    def testExampleRules(self):
</ins><span class="cx"> 
</span><del>-        recur = Recurrence()
-        recur.parse(&quot;FREQ=MONTHLY&quot;)
-        start = DateTime(2014, 1, 31, 12, 0, 0)
-        end = DateTime(2015, 1, 1, 0, 0, 0)
-        items = []
-        range = Period(start, end)
-        recur.expand(start, range, items)
-        self.assertEqual(
-            items,
-            [
-                DateTime(2014, 1, 31, 12, 0, 0),
-                DateTime(2014, 3, 31, 12, 0, 0),
-                DateTime(2014, 5, 31, 12, 0, 0),
-                DateTime(2014, 7, 31, 12, 0, 0),
-                DateTime(2014, 8, 31, 12, 0, 0),
-                DateTime(2014, 10, 31, 12, 0, 0),
-                DateTime(2014, 12, 31, 12, 0, 0),
-            ],
-        )
</del><ins>+        examples = os.path.join(os.path.dirname(__file__), &quot;rrule_examples.json&quot;)
+        with open(examples) as f:
+            examples = json.loads(f.read())
</ins><span class="cx"> 
</span><ins>+        for ctr, i in enumerate(examples):
</ins><span class="cx"> 
</span><del>-    def testMonthlyByMonthDay31(self):
</del><ins>+            recur = Recurrence()
+            recur.parse(i[&quot;rule&quot;])
+            start = DateTime.parseText(i[&quot;start&quot;])
+            end = DateTime.parseText(i[&quot;end&quot;])
+            results = map(DateTime.parseText, i[&quot;results&quot;])
</ins><span class="cx"> 
</span><del>-        recur = Recurrence()
-        recur.parse(&quot;FREQ=MONTHLY;BYMONTHDAY=31&quot;)
-        start = DateTime(2014, 1, 31, 12, 0, 0)
-        end = DateTime(2015, 1, 1, 0, 0, 0)
-        items = []
-        range = Period(start, end)
-        recur.expand(start, range, items)
-        self.assertEqual(
-            items,
-            [
-                DateTime(2014, 1, 31, 12, 0, 0),
-                DateTime(2014, 3, 31, 12, 0, 0),
-                DateTime(2014, 5, 31, 12, 0, 0),
-                DateTime(2014, 7, 31, 12, 0, 0),
-                DateTime(2014, 8, 31, 12, 0, 0),
-                DateTime(2014, 10, 31, 12, 0, 0),
-                DateTime(2014, 12, 31, 12, 0, 0),
-            ],
-        )
</del><ins>+            items = []
+            range = Period(start, end)
+            recur.expand(start, range, items)
+            self.assertEqual(
+                items,
+                results,
+                msg=&quot;Failed rule: #{} {}&quot;.format(ctr + 1, i[&quot;rule&quot;])
+            )
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def testMonthlyByMonthDayMinus31(self):
-
-        recur = Recurrence()
-        recur.parse(&quot;FREQ=MONTHLY;BYMONTHDAY=-31&quot;)
-        start = DateTime(2014, 1, 1, 12, 0, 0)
-        end = DateTime(2015, 1, 1, 0, 0, 0)
-        items = []
-        range = Period(start, end)
-        recur.expand(start, range, items)
-        self.assertEqual(
-            items,
-            [
-                DateTime(2014, 1, 1, 12, 0, 0),
-                DateTime(2014, 3, 1, 12, 0, 0),
-                DateTime(2014, 5, 1, 12, 0, 0),
-                DateTime(2014, 7, 1, 12, 0, 0),
-                DateTime(2014, 8, 1, 12, 0, 0),
-                DateTime(2014, 10, 1, 12, 0, 0),
-                DateTime(2014, 12, 1, 12, 0, 0),
-            ],
-        )
-
-
-    def testMonthlyByLastFridayExpand(self):
-
-        recur = Recurrence()
-        recur.parse(&quot;FREQ=MONTHLY;BYDAY=-1FR&quot;)
-        start = DateTime(2014, 1, 31, 12, 0, 0)
-        end = DateTime(2015, 1, 1, 0, 0, 0)
-        items = []
-        range = Period(start, end)
-        recur.expand(start, range, items)
-        self.assertEqual(
-            items,
-            [
-                DateTime(2014, 1, 31, 12, 0, 0),
-                DateTime(2014, 2, 28, 12, 0, 0),
-                DateTime(2014, 3, 28, 12, 0, 0),
-                DateTime(2014, 4, 25, 12, 0, 0),
-                DateTime(2014, 5, 30, 12, 0, 0),
-                DateTime(2014, 6, 27, 12, 0, 0),
-                DateTime(2014, 7, 25, 12, 0, 0),
-                DateTime(2014, 8, 29, 12, 0, 0),
-                DateTime(2014, 9, 26, 12, 0, 0),
-                DateTime(2014, 10, 31, 12, 0, 0),
-                DateTime(2014, 11, 28, 12, 0, 0),
-                DateTime(2014, 12, 26, 12, 0, 0),
-            ],
-        )
-
-
-    def testMonthlyByFifthFridayExpand(self):
-
-        recur = Recurrence()
-        recur.parse(&quot;FREQ=MONTHLY;BYDAY=5FR&quot;)
-        start = DateTime(2014, 1, 31, 12, 0, 0)
-        end = DateTime(2015, 1, 1, 0, 0, 0)
-        items = []
-        range = Period(start, end)
-        recur.expand(start, range, items)
-        self.assertEqual(
-            items,
-            [
-                DateTime(2014, 1, 31, 12, 0, 0),
-                DateTime(2014, 5, 30, 12, 0, 0),
-                DateTime(2014, 8, 29, 12, 0, 0),
-                DateTime(2014, 10, 31, 12, 0, 0),
-            ],
-        )
-
-
-    def testYearlyLeapDay(self):
-
-        recur = Recurrence()
-        recur.parse(&quot;FREQ=YEARLY&quot;)
-        start = DateTime(2012, 2, 29, 12, 0, 0)
-        end = DateTime(2020, 1, 1, 0, 0, 0)
-        items = []
-        range = Period(start, end)
-        recur.expand(start, range, items)
-        self.assertEqual(
-            items,
-            [
-                DateTime(2012, 2, 29, 12, 0, 0),
-                DateTime(2016, 2, 29, 12, 0, 0),
-            ],
-        )
-
-
-    def testYearlyYearDay(self):
-
-        recur = Recurrence()
-        recur.parse(&quot;FREQ=YEARLY;BYYEARDAY=366&quot;)
-        start = DateTime(2012, 12, 31, 12, 0, 0)
-        end = DateTime(2020, 1, 1, 0, 0, 0)
-        items = []
-        range = Period(start, end)
-        recur.expand(start, range, items)
-        self.assertEqual(
-            items,
-            [
-                DateTime(2012, 12, 31, 12, 0, 0),
-                DateTime(2016, 12, 31, 12, 0, 0),
-            ],
-        )
-
-
</del><span class="cx">     def testClearOnChange(self):
</span><span class="cx"> 
</span><span class="cx">         recur = Recurrence()
</span></span></pre>
</div>
</div>

</body>
</html>