Skip to content

Commit b501799

Browse files
authored
Merge pull request #3 from eficode/rf_exercises
Add Robot Framework exercises
2 parents fdbf101 + 9f140e3 commit b501799

File tree

5 files changed

+132
-0
lines changed

5 files changed

+132
-0
lines changed
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# METAR Reader Test Cases
2+
3+
## Goal
4+
5+
The goal is to create Robot Framework test cases using copilot when the starting point is
6+
only some sample data.
7+
8+
## Exericses
9+
10+
### 1. Use copilot to see what the `data` folder contains
11+
12+
Take a look at the `data` folder and ask copilot to explain what it contains. See how
13+
copilot can identify the contents and parse it for you using just the sample data.
14+
15+
---
16+
17+
### 2. Implement `MetarReader.py` based on `tests/test_metarreader.py`
18+
19+
The `MetarReader` library needs to satisfy the following functional requirements:
20+
21+
- **Data Management**
22+
- The system should read METAR data from a file and store it internally.
23+
- Each METAR entry should be associated with a unique site identifier.
24+
- The system should count the number of unique sites.
25+
26+
- **Site Existence**
27+
- The system should check if a site exists.
28+
- The system should check if a site does not exist.
29+
- If a site is expected to exist but does not, the system should raise an error.
30+
- If a site is expected not to exist but does, the system should raise an error.
31+
32+
- **Precipitation Check**
33+
- The system should check if it is raining at a specific site.
34+
- If it is expected to rain at a site but does not, the system should raise an error.
35+
- If it is not expected to rain at a site but does, the system should raise an error.
36+
37+
- **Remarks Handling**
38+
- The system should retrieve remarks for a specific site.
39+
- If remarks are expected for a site but do not exist, the system should raise an error.
40+
- If remarks are not expected for a site but exist, the system should raise an error.
41+
- The system should check if a site has a specific remark (e.g., "AO2" for precipitation sensor).
42+
43+
The unit tests for the `MetarReader` library are already implemented in
44+
`tests/test_metarreader.py`. Once your library is ready, the unit tests should pass.
45+
46+
To increase readability of the library, ensure the methods that are intended to be keywords
47+
have the `robot.api.deco.keyword` decorator.
48+
49+
---
50+
51+
### 3. Implement Robot Framework tests based on functional requirements
52+
53+
The Robot Framework test suite `metar_test.robot` must test the following cases:
54+
55+
- **METAR File Contains Data**
56+
- Initially, the number of sites should be `0`.
57+
- After adding data from `metar_data.txt`, the number of sites should be `6`.
58+
59+
- **Can Find Entry**
60+
- Initially, the site `KCPW` should not exist.
61+
- Expect an error when checking if the site `KCPW` exists.
62+
- After adding data from metar_data.txt, the site `KCPW` should exist.
63+
- Expect an error when checking if the site `KCPW` does not exist.
64+
65+
- **Can Check for Rain**
66+
- Expect an error when checking if it should rain at `MYEG`.
67+
- Expect an error when checking if it should rain at `KFKA`.
68+
- After adding data from `metar_data.txt`, it should rain at `KFKA`.
69+
- Expect an error when checking if it should rain at `MYEG`.
70+
71+
- **Get Remarks**
72+
- Expect an error when checking if the site `KEHY` has a precipitation sensor.
73+
- Expect an error when checking if the site `KFDW` has a precipitation sensor.
74+
- After adding data from `metar_data.txt`, the site `KEHY` should have a precipitation sensor.
75+
- Expect an error when checking if the site `KFDW` has a precipitation sensor.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
MYEG 251359Z AUTO 09009KT 10SM SCT029 27/20 A2998 RMK AO2
2+
KVTP 251358Z AUTO 23010G16KT 10SM CLR 00/M03 A3016 RMK AO2
3+
KEHY 251428Z AUTO 26018G25KT 10SM CLR 06/M01 A3009 RMK AO2 T00551007
4+
KFKA 251348Z AUTO 05009G15KT 7SM RA SCT010 BKN015 OVC044 10/08 A2977 RMK AO2 LTG DSNT E P0002 T01000075
5+
KCPW 251347Z AUTO 36003KT 10SM CLR 00/M07 A3025 RMK AO2
6+
KFDW 251355Z AUTO 22004KT 10SM CLR 29/15 A3000 RMK AO1
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class MetarReader(object):
2+
3+
def __init__(self):
4+
pass
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*** Settings ***
2+
Library MetarReader
3+
4+
*** Test Cases ***
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import unittest
2+
from metarreader import MetarReader
3+
4+
class TestMetarReader(unittest.TestCase):
5+
6+
def setUp(self):
7+
self.reader = MetarReader()
8+
self.sample_data = [
9+
"SITE1 RA RMK Remark1",
10+
"SITE2 RMK Remark2",
11+
"SITE3"
12+
]
13+
self.reader._add_lines(self.sample_data)
14+
15+
def test_add_data(self):
16+
self.reader.add_data('sample_metar.txt')
17+
self.assertEqual(self.reader.get_number_of_sites(), 3)
18+
19+
def test_get_number_of_sites(self):
20+
self.assertEqual(self.reader.get_number_of_sites(), 3)
21+
22+
def test_site_should_not_exist(self):
23+
with self.assertRaises(AssertionError):
24+
self.reader.site_should_not_exist("SITE1")
25+
26+
def test_site_should_exist(self):
27+
self.reader.site_should_exist("SITE1")
28+
with self.assertRaises(AssertionError):
29+
self.reader.site_should_exist("SITE4")
30+
31+
def test_it_should_rain(self):
32+
self.reader.it_should_rain("SITE1")
33+
with self.assertRaises(AssertionError):
34+
self.reader.it_should_rain("SITE2")
35+
36+
def test_get_remarks(self):
37+
self.assertEqual(self.reader.get_remarks("SITE1"), ["Remark1"])
38+
self.assertEqual(self.reader.get_remarks("SITE2"), ["Remark2"])
39+
with self.assertRaises(AssertionError):
40+
self.reader.get_remarks("SITE3")
41+
42+
if __name__ == '__main__':
43+
unittest.main()

0 commit comments

Comments
 (0)