python-caldav / caldav

Apache License 2.0
313 stars 91 forks source link

Add example in test for stamped initialization issue from #347 #350

Closed yuwash closed 7 months ago

yuwash commented 7 months ago

The pull request #347 didn’t contain a test that showed the difference, so here it is. Without the fix, the test would’ve failed like:

…
            for ical in non_broken_ical:                                            
>               assert vcal.fix(ical) == ical

tests/test_vcal.py:262:                                                             
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
caldav/lib/vcal.py:81: in fix             
    "\n".join(filter(LineFilterDiscardingDuplicates(), fixed.strip().split("\n")))  
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <caldav.lib.vcal.LineFilterDiscardingDuplicates object at 0x7a99fd022820>    
line = 'DTSTAMP:20210205T101751Z'                                                   

    def __call__(self, line):                                                       
        if line.startswith("BEGIN:V"):                                              
            self.stamped = 0                                                                                                                                            
            self.ended = 0                                                          

        elif re.match("(DURATION|DTEND|DUE)[:;]", line):
            if self.ended:
                return False
            self.ended += 1

        elif re.match("DTSTAMP[:;]", line):
>           if self.stamped:
E           AttributeError: 'LineFilterDiscardingDuplicates' object has no attribute 'stamped'

caldav/lib/vcal.py:141: AttributeError
tobixen commented 7 months ago

Perfect. This closes #349

tobixen commented 7 months ago

While it also would be nice with some unit test exercising the new class specifically, I believe it should already be more or less covered by existing tests.