Skip to content

Commit

Permalink
Merge pull request #7 from anguskbell/feature/updates-for-post-pub-ch…
Browse files Browse the repository at this point in the history
…ecks-2

Misc changes to support post publishing checks
  • Loading branch information
ciaranmccormick authored May 12, 2022
2 parents 0e22a54 + d2c6341 commit 9646750
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 18 deletions.
16 changes: 1 addition & 15 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ pyproj = "^3.3.0"
python-dateutil = "^2.8.2"
requests = "^2.27.1"
shapely-geojson = "^0.0.1"
ordered-enum = "^0.0.6"

[tool.poetry.dev-dependencies]
Sphinx = "^4.4.0"
Expand Down
6 changes: 5 additions & 1 deletion pytxc/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __repr__(self):
class_name = self.__class__.__name__
attrs = []
if self.text:
attrs.append("text={self.text!r}")
attrs.append(f"text={self.text!r}")
attrs += [f"{key}={value!r}" for key, value in self.attributes.items()]
attrs_str = ", ".join(attrs)
return f"{class_name}({attrs_str})"
Expand Down Expand Up @@ -75,6 +75,10 @@ def get_children(self) -> List["Element"]:
def get_root(self) -> "Element":
return Element(self._element.getroottree().getroot())

@property
def line_number(self) -> Optional[int]:
return self._element.sourceline # type: ignore


E = TypeVar("E", bound=Element)

Expand Down
16 changes: 16 additions & 0 deletions pytxc/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ class DayOfWeek(Enum):
saturday = "Saturday"
sunday = "Sunday"

@classmethod
def from_weekday_int(cls, weekday: int) -> "DayOfWeek":
"""Create DayOfWeek object from zero-based integer, compatible with
library method date.weekday()
"""
map = {
0: cls.monday,
1: cls.tuesday,
2: cls.wednesday,
3: cls.thursday,
4: cls.friday,
5: cls.saturday,
6: cls.sunday
}
return map[weekday]


class OperatingProfile(Element):
def __repr__(self) -> str:
Expand Down
10 changes: 9 additions & 1 deletion pytxc/vehicles.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from .elements import Element
from .journeys import JourneyPatternRef, JourneyPatternTimingLinkRef
from .operators import OperatorRef
from .services import LineRef, ServiceRef
from .services import LineRef, OperatingProfile, ServiceRef


class Block(Element):
Expand Down Expand Up @@ -110,3 +110,11 @@ def departure_time(self) -> Optional[time]:
def timing_links(self) -> List[VehicleJourneyTimingLink]:
path = "VehicleJourneyTimingLink"
return [VehicleJourneyTimingLink(element) for element in self.find_all(path)]

@property
def operating_profile(self) -> Optional[OperatingProfile]:
path = "OperatingProfile"
element = self.find(path)
if element is not None:
return OperatingProfile(element)
return None
6 changes: 6 additions & 0 deletions tests/test_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,9 @@ def test_text_none():
element = etree.fromstring(element_str)
element.text = None
assert Element(element).text is None


def test_line_number(txc_file):
timetable = Timetable.from_file(txc_file)
first_stop_point = timetable.stop_points[0]
assert first_stop_point.line_number == 5
20 changes: 20 additions & 0 deletions tests/test_journeys.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ def test_vehicle_journeys(txc_file):
block = operational.block
assert block is None

operating_profile = journey.operating_profile
assert operating_profile is not None
assert operating_profile.holidays_only


def test_journey_pattern_timing_link_none():
jp_timing_link_str = """
Expand Down Expand Up @@ -164,3 +168,19 @@ def test_vehicle_journey_none_children():

assert vehicle_journey.operational is None
assert vehicle_journey.departure_time is None


def test_operating_profile_none():
vehicle_journey_str = """
<VehicleJourney xmlns="http://www.transxchange.org.uk/">
<OperatingProphet>
<RegularDayType>
<HolidaysOnly/>
</RegularDayType>
</OperatingProphet>
</VehicleJourney>
"""
element = etree.fromstring(vehicle_journey_str)
vehicle_journey = VehicleJourney(element)
operating_profile = vehicle_journey.operating_profile
assert operating_profile is None
7 changes: 7 additions & 0 deletions tests/test_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,10 @@ def test_operating_profile_week_days():
assert DayOfWeek.thursday in days_of_week
assert DayOfWeek.friday in days_of_week
assert operating_profile.holidays_only is False


def test_day_of_week_from_int():
day = DayOfWeek.from_weekday_int(0)
assert day == DayOfWeek.monday
day = DayOfWeek.from_weekday_int(6)
assert day == DayOfWeek.sunday

0 comments on commit 9646750

Please sign in to comment.