~ed.so/duplicity/move_netloc

« back to all changes in this revision

Viewing changes to testing/unit/test_dup_time.py

  • Committer: Kenneth Loafman
  • Date: 2014-12-12 14:39:54 UTC
  • Revision ID: kenneth@loafman.com-20141212143954-wyln65yd1ynzsrlx
* Source formatted, using PyDev, all source files to fix some easily fixed
  PEP8 issues. Use ignore space when comparing against previous versions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
    def testCmp(self):
45
45
        """Test time comparisons"""
46
46
        cmp = dup_time.cmp
47
 
        assert cmp(1,2) == -1
48
 
        assert cmp(2,2) == 0
49
 
        assert cmp(5,1) == 1
 
47
        assert cmp(1, 2) == -1
 
48
        assert cmp(2, 2) == 0
 
49
        assert cmp(5, 1) == 1
50
50
        assert cmp("2001-09-01T21:49:04Z", "2001-08-01T21:49:04Z") == 1
51
51
        assert cmp("2001-09-01T04:49:04+03:23", "2001-09-01T21:49:04Z") == -1
52
52
        assert cmp("2001-09-01T12:00:00Z", "2001-09-01T04:00:00-08:00") == 0
59
59
        """Like testCmp but with new separator"""
60
60
        self.set_global('time_separator', "_")
61
61
        cmp = dup_time.cmp
62
 
        assert cmp(1,2) == -1
63
 
        assert cmp(2,2) == 0
64
 
        assert cmp(5,1) == 1
 
62
        assert cmp(1, 2) == -1
 
63
        assert cmp(2, 2) == 0
 
64
        assert cmp(5, 1) == 1
65
65
        assert cmp("2001-09-01T21_49_04Z", "2001-08-01T21_49_04Z") == 1
66
66
        assert cmp("2001-09-01T04_49_04+03_23", "2001-09-01T21_49_04Z") == -1
67
67
        assert cmp("2001-09-01T12_00_00Z", "2001-09-01T04_00_00-08_00") == 0
82
82
            try: i2s(s)
83
83
            except dup_time.TimeException: pass
84
84
            else: assert 0, s
85
 
        assert i2s("7D") == 7*86400
 
85
        assert i2s("7D") == 7 * 86400
86
86
        assert i2s("232s") == 232
87
 
        assert i2s("2M") == 2*30*86400
88
 
        assert i2s("400m") == 400*60
89
 
        assert i2s("1Y") == 365*86400
90
 
        assert i2s("30h") == 30*60*60
91
 
        assert i2s("3W") == 3*7*86400
 
87
        assert i2s("2M") == 2 * 30 * 86400
 
88
        assert i2s("400m") == 400 * 60
 
89
        assert i2s("1Y") == 365 * 86400
 
90
        assert i2s("30h") == 30 * 60 * 60
 
91
        assert i2s("3W") == 3 * 7 * 86400
92
92
 
93
93
    def testIntervalsComposite(self):
94
94
        """Like above, but allow composite intervals"""
95
95
        i2s = dup_time.intstringtoseconds
96
 
        assert i2s("7D2h") == 7*86400 + 2*3600
97
 
        assert i2s("2Y3s") == 2*365*86400 + 3
98
 
        assert i2s("1M2W4D2h5m20s") == (30*86400 + 2*7*86400 + 4*86400 +
99
 
                                        2*3600 + 5*60 + 20)
 
96
        assert i2s("7D2h") == 7 * 86400 + 2 * 3600
 
97
        assert i2s("2Y3s") == 2 * 365 * 86400 + 3
 
98
        assert i2s("1M2W4D2h5m20s") == (30 * 86400 + 2 * 7 * 86400 + 4 * 86400 + 
 
99
                                        2 * 3600 + 5 * 60 + 20)
100
100
 
101
101
    def testPrettyIntervals(self):
102
102
        """Test printable interval conversion"""
111
111
        """Test genstrtotime, conversion of arbitrary string to time"""
112
112
        g2t = dup_time.genstrtotime
113
113
        assert g2t('now', 1000) == 1000
114
 
        assert g2t('2h3s', 10000) == 10000 - 2*3600 - 3
 
114
        assert g2t('2h3s', 10000) == 10000 - 2 * 3600 - 3
115
115
        assert g2t('2001-09-01T21:49:04Z') == \
116
116
               dup_time.stringtotime('2001-09-01T21:49:04Z')
117
117
        assert g2t('2002-04-26T04:22:01') == \