Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: beautify parsers docstring in src and test #53

Merged
merged 1 commit into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions src/bmkg/parsers/parse_area_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ def parse_area_element(element: Element) -> Area:
>>> from defusedxml.ElementTree import fromstring
>>> element = fromstring(
... "<area"
... ' id="501409"'
... ' latitude="4.176594"'
... ' longitude="96.124878"'
... ' coordinate="96.124878 4.176594"'
... ' type="land"'
... ' region=""'
... ' level="1"'
... ' description="Aceh Barat"'
... ' domain="Aceh"'
... ' tags=""'
... ' id="501409"'
... ' latitude="4.176594"'
... ' longitude="96.124878"'
... ' coordinate="96.124878 4.176594"'
... ' type="land"'
... ' region=""'
... ' level="1"'
... ' description="Aceh Barat"'
... ' domain="Aceh"'
... ' tags=""'
... ">"
... '<name xml:lang="en_US">Aceh Barat</name>'
... '<name xml:lang="id_ID">Kab. Aceh Barat</name>'
... ' <name xml:lang="en_US">Aceh Barat</name>'
... ' <name xml:lang="id_ID">Kab. Aceh Barat</name>'
... "</area>"
... )
>>> area = parse_area_element(element)
Expand Down
36 changes: 18 additions & 18 deletions src/bmkg/parsers/parse_datetime_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,24 @@ def parse_datetime_element(element: Element) -> Iterator[datetime]:
>>> from defusedxml.ElementTree import fromstring
>>> element = fromstring(
... '<parameter id="ws" description="datetime" type="hourly">'
... '<timerange type="hourly" h="0" datetime="202401170000">'
... '<value unit="Kt">5</value>'
... '<value unit="MPH">5.75389725</value>'
... '<value unit="KPH">9.26</value>'
... '<value unit="MS">2.57222222</value>'
... "</timerange>"
... '<timerange type="hourly" h="6" datetime="202401170600">'
... '<value unit="Kt">2</value>'
... '<value unit="MPH">2.3015589</value>'
... '<value unit="KPH">3.704</value>'
... '<value unit="MS">1.028888888</value>'
... "</timerange>"
... '<timerange type="hourly" h="12" datetime="202401171200">'
... '<value unit="Kt">0</value>'
... '<value unit="MPH">0</value>'
... '<value unit="KPH">0</value>'
... '<value unit="MS">0</value>'
... "</timerange>"
... ' <timerange type="hourly" h="0" datetime="202401170000">'
... ' <value unit="Kt">5</value>'
... ' <value unit="MPH">5.75389725</value>'
... ' <value unit="KPH">9.26</value>'
... ' <value unit="MS">2.57222222</value>'
... " </timerange>"
... ' <timerange type="hourly" h="6" datetime="202401170600">'
... ' <value unit="Kt">2</value>'
... ' <value unit="MPH">2.3015589</value>'
... ' <value unit="KPH">3.704</value>'
... ' <value unit="MS">1.028888888</value>'
... " </timerange>"
... ' <timerange type="hourly" h="12" datetime="202401171200">'
... ' <value unit="Kt">0</value>'
... ' <value unit="MPH">0</value>'
... ' <value unit="KPH">0</value>'
... ' <value unit="MS">0</value>'
... " </timerange>"
... "</parameter>"
... )
>>> datetime = parse_datetime_element(element)
Expand Down
18 changes: 9 additions & 9 deletions src/bmkg/parsers/parse_humidity_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def parse_humidity_element(element: Element) -> Iterator[Humidity]:
>>> from defusedxml.ElementTree import fromstring
>>> element = fromstring(
... '<parameter id="hu" description="Humidity" type="hourly">'
... '<timerange type="hourly" h="0" datetime="202401170000">'
... '<value unit="%">95</value>'
... "</timerange>"
... '<timerange type="hourly" h="6" datetime="202401170600">'
... '<value unit="%">90</value>'
... "</timerange>"
... '<timerange type="hourly" h="12" datetime="202401171200">'
... '<value unit="%">95</value>'
... "</timerange>"
... ' <timerange type="hourly" h="0" datetime="202401170000">'
... ' <value unit="%">95</value>'
... " </timerange>"
... ' <timerange type="hourly" h="6" datetime="202401170600">'
... ' <value unit="%">90</value>'
... " </timerange>"
... ' <timerange type="hourly" h="12" datetime="202401171200">'
... ' <value unit="%">95</value>'
... " </timerange>"
... "</parameter>"
... )
>>> humidity = parse_humidity_element(element)
Expand Down
14 changes: 7 additions & 7 deletions src/bmkg/parsers/parse_issue_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ def parse_issue_element(element: Element) -> datetime:
>>> from defusedxml.ElementTree import fromstring
>>> element = fromstring(
... "<issue>"
... "<timestamp>20240116032347</timestamp>"
... "<year>2024</year>"
... "<month>01</month>"
... "<day>16</day>"
... "<hour>03</hour>"
... "<minute>23</minute>"
... "<second>47</second>"
... " <timestamp>20240116032347</timestamp>"
... " <year>2024</year>"
... " <month>01</month>"
... " <day>16</day>"
... " <hour>03</hour>"
... " <minute>23</minute>"
... " <second>47</second>"
... "</issue>"
... )
>>> issue = parse_issue_element(element)
Expand Down
24 changes: 12 additions & 12 deletions src/bmkg/parsers/parse_temperature_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ def parse_temperature_element(element: Element) -> Iterator[Temperature]:
>>> from defusedxml.ElementTree import fromstring
>>> element = fromstring(
... '<parameter id="t" description="Temperature" type="hourly">'
... '<timerange type="hourly" h="0" datetime="202401170000">'
... '<value unit="C">24</value>'
... '<value unit="F">75.2</value>'
... "</timerange>"
... '<timerange type="hourly" h="6" datetime="202401170600">'
... '<value unit="C">28</value>'
... '<value unit="F">82.4</value>'
... "</timerange>"
... '<timerange type="hourly" h="12" datetime="202401171200">'
... '<value unit="C">26</value>'
... '<value unit="F">78.8</value>'
... "</timerange>"
... ' <timerange type="hourly" h="0" datetime="202401170000">'
... ' <value unit="C">24</value>'
... ' <value unit="F">75.2</value>'
... " </timerange>"
... ' <timerange type="hourly" h="6" datetime="202401170600">'
... ' <value unit="C">28</value>'
... ' <value unit="F">82.4</value>'
... " </timerange>"
... ' <timerange type="hourly" h="12" datetime="202401171200">'
... ' <value unit="C">26</value>'
... ' <value unit="F">78.8</value>'
... " </timerange>"
... "</parameter>"
... )
>>> temperature = parse_temperature_element(element)
Expand Down
18 changes: 9 additions & 9 deletions src/bmkg/parsers/parse_weather_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ def parse_weather_element(element: Element) -> Iterator[enums.Weather]:
>>> from defusedxml.ElementTree import fromstring
>>> element = fromstring(
... '<parameter id="weather" description="Weather" type="hourly">'
... '<timerange type="hourly" h="0" datetime="202401170000">'
... '<value unit="icon">60</value>'
... "</timerange>"
... '<timerange type="hourly" h="6" datetime="202401170600">'
... '<value unit="icon">60</value>'
... "</timerange>"
... '<timerange type="hourly" h="12" datetime="202401171200">'
... '<value unit="icon">1</value>'
... "</timerange>"
... ' <timerange type="hourly" h="0" datetime="202401170000">'
... ' <value unit="icon">60</value>'
... " </timerange>"
... ' <timerange type="hourly" h="6" datetime="202401170600">'
... ' <value unit="icon">60</value>'
... " </timerange>"
... ' <timerange type="hourly" h="12" datetime="202401171200">'
... ' <value unit="icon">1</value>'
... " </timerange>"
... "</parameter>"
... )
>>> weather = parse_weather_element(element)
Expand Down
30 changes: 15 additions & 15 deletions src/bmkg/parsers/parse_wind_direction_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ def parse_wind_direction_element(element: Element) -> Iterator[WindDirection]:
>>> from defusedxml.ElementTree import fromstring
>>> element = fromstring(
... '<parameter id="wd" description="Wind direction" type="hourly">'
... '<timerange type="hourly" h="0" datetime="202401170000">'
... '<value unit="deg">90</value>'
... '<value unit="CARD">E</value>'
... '<value unit="SEXA">9000</value>'
... "</timerange>"
... '<timerange type="hourly" h="6" datetime="202401170600">'
... '<value unit="deg">157.5</value>'
... '<value unit="CARD">SSE</value>'
... '<value unit="SEXA">15730</value>'
... "</timerange>"
... '<timerange type="hourly" h="12" datetime="202401171200">'
... '<value unit="deg">0</value>'
... '<value unit="CARD">VARIABLE</value>'
... '<value unit="SEXA">000</value>'
... "</timerange>"
... ' <timerange type="hourly" h="0" datetime="202401170000">'
... ' <value unit="deg">90</value>'
... ' <value unit="CARD">E</value>'
... ' <value unit="SEXA">9000</value>'
... " </timerange>"
... ' <timerange type="hourly" h="6" datetime="202401170600">'
... ' <value unit="deg">157.5</value>'
... ' <value unit="CARD">SSE</value>'
... ' <value unit="SEXA">15730</value>'
... " </timerange>"
... ' <timerange type="hourly" h="12" datetime="202401171200">'
... ' <value unit="deg">0</value>'
... ' <value unit="CARD">VARIABLE</value>'
... ' <value unit="SEXA">000</value>'
... " </timerange>"
... "</parameter>"
... )
>>> wind_direction = parse_wind_direction_element(element)
Expand Down
36 changes: 18 additions & 18 deletions src/bmkg/parsers/parse_wind_speed_element.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,24 @@ def parse_wind_speed_element(element: Element) -> Iterator[WindSpeed]:
>>> from defusedxml.ElementTree import fromstring
>>> element = fromstring(
... '<parameter id="ws" description="Wind speed" type="hourly">'
... '<timerange type="hourly" h="0" datetime="202401170000">'
... '<value unit="Kt">5</value>'
... '<value unit="MPH">5.75389725</value>'
... '<value unit="KPH">9.26</value>'
... '<value unit="MS">2.57222222</value>'
... "</timerange>"
... '<timerange type="hourly" h="6" datetime="202401170600">'
... '<value unit="Kt">2</value>'
... '<value unit="MPH">2.3015589</value>'
... '<value unit="KPH">3.704</value>'
... '<value unit="MS">1.028888888</value>'
... "</timerange>"
... '<timerange type="hourly" h="12" datetime="202401171200">'
... '<value unit="Kt">0</value>'
... '<value unit="MPH">0</value>'
... '<value unit="KPH">0</value>'
... '<value unit="MS">0</value>'
... "</timerange>"
... ' <timerange type="hourly" h="0" datetime="202401170000">'
... ' <value unit="Kt">5</value>'
... ' <value unit="MPH">5.75389725</value>'
... ' <value unit="KPH">9.26</value>'
... ' <value unit="MS">2.57222222</value>'
... " </timerange>"
... ' <timerange type="hourly" h="6" datetime="202401170600">'
... ' <value unit="Kt">2</value>'
... ' <value unit="MPH">2.3015589</value>'
... ' <value unit="KPH">3.704</value>'
... ' <value unit="MS">1.028888888</value>'
... " </timerange>"
... ' <timerange type="hourly" h="12" datetime="202401171200">'
... ' <value unit="Kt">0</value>'
... ' <value unit="MPH">0</value>'
... ' <value unit="KPH">0</value>'
... ' <value unit="MS">0</value>'
... " </timerange>"
... "</parameter>"
... )
>>> wind_speed = parse_wind_speed_element(element)
Expand Down
56 changes: 28 additions & 28 deletions tests/test_parsers/test_parse_weather_forecast_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,33 @@ def test_parse_element_with_invalid_attribute():
):
parse_weather_forecast_data(
'<data source="meteofactory" productioncenter="NC Jakarta">'
"<forecast domain='local'>"
"<issue>"
"<timestamp>20240216023745</timestamp>"
"<year>2024</year>"
"<month>02</month>"
"<day>16</day>"
"<hour>02</hour>"
"<minute>37</minute>"
"<second>45</second>"
"</issue>"
"<area"
' id="501409"'
' latitude="4.176594"'
' longitude="96.124878"'
' coordinate="96.124878 4.176594"'
' type="land"'
' region=""'
' level="1"'
' description="Aceh Barat"'
' domain="Aceh"'
' tags=""'
">"
'<name xml:lang="en_US">Aceh Barat</name>'
'<name xml:lang="id_ID">Kab. Aceh Barat</name>'
'<parameter description="Humidity" type="hourly">'
"</parameter>"
"</area>"
"</forecast>"
" <forecast domain='local'>"
" <issue>"
" <timestamp>20240216023745</timestamp>"
" <year>2024</year>"
" <month>02</month>"
" <day>16</day>"
" <hour>02</hour>"
" <minute>37</minute>"
" <second>45</second>"
" </issue>"
" <area"
' id="501409"'
' latitude="4.176594"'
' longitude="96.124878"'
' coordinate="96.124878 4.176594"'
' type="land"'
' region=""'
' level="1"'
' description="Aceh Barat"'
' domain="Aceh"'
' tags=""'
" >"
' <name xml:lang="en_US">Aceh Barat</name>'
' <name xml:lang="id_ID">Kab. Aceh Barat</name>'
' <parameter description="Humidity" type="hourly">'
" </parameter>"
" </area>"
" </forecast>"
"</data>"
)
Loading