kopia lustrzana https://github.com/collective/icalendar
				
				
				
			Add `sign` and `weekday` attributes to `vWeekday` components
							rodzic
							
								
									c59966c7d9
								
							
						
					
					
						commit
						71c6952bee
					
				| 
						 | 
				
			
			@ -6,7 +6,7 @@ Changelog
 | 
			
		|||
 | 
			
		||||
Minor changes:
 | 
			
		||||
 | 
			
		||||
- ...
 | 
			
		||||
- Add ``sign`` and ``weekday`` attributes to ``vWeekday`` components. See `Issue 749 <https://github.com/collective/icalendar/issues/749>`_.
 | 
			
		||||
 | 
			
		||||
Breaking changes:
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -77,6 +77,7 @@ icalendar contributors
 | 
			
		|||
- Jeffrey Whewhetu <jeffwhewhetu@gmail.com>
 | 
			
		||||
- `Soham Dutta <https://github.com/NP-compete>`_
 | 
			
		||||
- `Serif OZ  <https://github.com/SerifOZ>`_
 | 
			
		||||
- David Venhoff <https://github.com/david-venhoff>
 | 
			
		||||
 | 
			
		||||
Find out who contributed::
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -931,6 +931,8 @@ class vWeekday(str):
 | 
			
		|||
        relative = match['relative']
 | 
			
		||||
        if weekday not in vWeekday.week_days or sign not in '+-':
 | 
			
		||||
            raise ValueError(f'Expected weekday abbrevation, got: {self}')
 | 
			
		||||
        self.sign = sign or None
 | 
			
		||||
        self.weekday = weekday or None
 | 
			
		||||
        self.relative = relative and int(relative) or None
 | 
			
		||||
        self.params = Parameters()
 | 
			
		||||
        return self
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,29 @@
 | 
			
		|||
import pytest
 | 
			
		||||
 | 
			
		||||
from icalendar.prop import vWeekday
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_simple():
 | 
			
		||||
    weekday = vWeekday("SU")
 | 
			
		||||
    assert weekday.to_ical() == b"SU"
 | 
			
		||||
    assert weekday.sign is None
 | 
			
		||||
    assert weekday.weekday == "SU"
 | 
			
		||||
    assert weekday.relative is None
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_relative():
 | 
			
		||||
    weekday = vWeekday("-1MO")
 | 
			
		||||
    assert weekday.to_ical() == b"-1MO"
 | 
			
		||||
    assert weekday.sign == "-"
 | 
			
		||||
    assert weekday.weekday == "MO"
 | 
			
		||||
    assert weekday.relative == 1
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_roundtrip():
 | 
			
		||||
    assert vWeekday.from_ical(vWeekday("+2TH").to_ical()) == "+2TH"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def test_error():
 | 
			
		||||
    """Error: Expected weekday abbrevation, got: \"-100MO\" """
 | 
			
		||||
    with pytest.raises(ValueError):
 | 
			
		||||
        vWeekday.from_ical("-100MO")
 | 
			
		||||
		Ładowanie…
	
		Reference in New Issue