コード例 #1
0
ファイル: tests.py プロジェクト: pombredanne/pythorg
 def setUp(self):
     self.filename = 'test.org'
     self.org_file = OrgFile(self.filename)
     self.first_heading = self.org_file.headings[0]
     self.second_heading = self.org_file.headings[1]
     self.third_heading = self.org_file.headings[3]
コード例 #2
0
ファイル: tests.py プロジェクト: pombredanne/pythorg
class OrgFileTestCase(unittest.TestCase):
    def setUp(self):
        self.filename = 'test.org'
        self.org_file = OrgFile(self.filename)
        self.first_heading = self.org_file.headings[0]
        self.second_heading = self.org_file.headings[1]
        self.third_heading = self.org_file.headings[3]

    def test_num_headings(self):
        assert(len(self.org_file.headings) == 11)

    def test_has_children(self):
        self.assertFalse(self.first_heading.has_children)
        self.assertTrue(self.second_heading.has_children)
        self.assertTrue(self.third_heading.has_children)

    def test_num_children(self):
        self.assertEqual(self.first_heading.num_children, 0)
        self.assertEqual(self.second_heading.num_children, 1)
        self.assertEqual(self.third_heading.num_children, 7)

    def test_first_heading_duration(self):
        assert(type(self.first_heading.duration) is timedelta)
        self.assertEqual(self.first_heading.duration, timedelta(0))

    def test_second_heading_duration(self):
        assert(type(self.second_heading.duration) is timedelta)
        self.assertEqual(self.second_heading.duration, timedelta(0, 4800))

    def test_third_heading_duration(self):
        assert(type(self.third_heading.duration) is timedelta)
        self.assertEqual(self.third_heading.duration, timedelta(1, 55140))

    def test_sorted_clocks(self):
        clocks = self.org_file.clocks
        assert(all(
            [clocks[i].clock_in <= clocks[i + 1].clock_in
                for i in xrange(len(clocks) - 1)]))

    def test_start_date(self):
        self.assertEqual(
            self.org_file.get_clock_index(start_date=datetime(2011, 9, 28)), 0)
        self.assertEqual(
            self.org_file.get_clock_index(start_date=datetime(2011, 10, 7)), 6)
        self.assertEqual(
            self.org_file.get_clock_index(
                start_date=datetime(2011, 10, 12)), 27)
        self.assertEqual(
            self.org_file.get_clock_index(
                start_date=datetime(2011, 10, 14)), 51)

    def test_end_date(self):
        self.assertEqual(
            self.org_file.get_clock_index(end_date=datetime(2011, 9, 30)), 0)
        self.assertEqual(
            self.org_file.get_clock_index(end_date=datetime(2011, 10, 8)), 22)
        self.assertEqual(
            self.org_file.get_clock_index(end_date=datetime(2011, 10, 13)), 41)
        self.assertEqual(
            self.org_file.get_clock_index(end_date=datetime(2011, 10, 15)), 53)

    def test_get_clocks_by_date_range(self):
        start_date = datetime(2011, 10, 7)
        end_date = datetime(2011, 10, 12)
        ranged_clocks = self.org_file.get_clocks_by_date_range(
            start_date=start_date, end_date=end_date)
        self.assertTrue(start_date <= ranged_clocks[0].clock_in)
        self.assertTrue(end_date >= ranged_clocks[-1].clock_in)

    def test_line_eq(self):
        string1 = '* Heading 1'
        string2 = '* Heading 2'
        self.assertEqual(Line(string1), Line(string1))
        self.assertNotEqual(Line(string1), Line(string2))