Skip to content

Commit

Permalink
Merge pull request #3 from eficode/rf_exercises
Browse files Browse the repository at this point in the history
Add Robot Framework exercises
  • Loading branch information
efiheko authored Dec 16, 2024
2 parents fdbf101 + 9f140e3 commit b501799
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 0 deletions.
75 changes: 75 additions & 0 deletions exercisefiles/robotframework/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# METAR Reader Test Cases

## Goal

The goal is to create Robot Framework test cases using copilot when the starting point is
only some sample data.

## Exericses

### 1. Use copilot to see what the `data` folder contains

Take a look at the `data` folder and ask copilot to explain what it contains. See how
copilot can identify the contents and parse it for you using just the sample data.

---

### 2. Implement `MetarReader.py` based on `tests/test_metarreader.py`

The `MetarReader` library needs to satisfy the following functional requirements:

- **Data Management**
- The system should read METAR data from a file and store it internally.
- Each METAR entry should be associated with a unique site identifier.
- The system should count the number of unique sites.

- **Site Existence**
- The system should check if a site exists.
- The system should check if a site does not exist.
- If a site is expected to exist but does not, the system should raise an error.
- If a site is expected not to exist but does, the system should raise an error.

- **Precipitation Check**
- The system should check if it is raining at a specific site.
- If it is expected to rain at a site but does not, the system should raise an error.
- If it is not expected to rain at a site but does, the system should raise an error.

- **Remarks Handling**
- The system should retrieve remarks for a specific site.
- If remarks are expected for a site but do not exist, the system should raise an error.
- If remarks are not expected for a site but exist, the system should raise an error.
- The system should check if a site has a specific remark (e.g., "AO2" for precipitation sensor).

The unit tests for the `MetarReader` library are already implemented in
`tests/test_metarreader.py`. Once your library is ready, the unit tests should pass.

To increase readability of the library, ensure the methods that are intended to be keywords
have the `robot.api.deco.keyword` decorator.

---

### 3. Implement Robot Framework tests based on functional requirements

The Robot Framework test suite `metar_test.robot` must test the following cases:

- **METAR File Contains Data**
- Initially, the number of sites should be `0`.
- After adding data from `metar_data.txt`, the number of sites should be `6`.

- **Can Find Entry**
- Initially, the site `KCPW` should not exist.
- Expect an error when checking if the site `KCPW` exists.
- After adding data from metar_data.txt, the site `KCPW` should exist.
- Expect an error when checking if the site `KCPW` does not exist.

- **Can Check for Rain**
- Expect an error when checking if it should rain at `MYEG`.
- Expect an error when checking if it should rain at `KFKA`.
- After adding data from `metar_data.txt`, it should rain at `KFKA`.
- Expect an error when checking if it should rain at `MYEG`.

- **Get Remarks**
- Expect an error when checking if the site `KEHY` has a precipitation sensor.
- Expect an error when checking if the site `KFDW` has a precipitation sensor.
- After adding data from `metar_data.txt`, the site `KEHY` should have a precipitation sensor.
- Expect an error when checking if the site `KFDW` has a precipitation sensor.
6 changes: 6 additions & 0 deletions exercisefiles/robotframework/data/metar_data.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MYEG 251359Z AUTO 09009KT 10SM SCT029 27/20 A2998 RMK AO2
KVTP 251358Z AUTO 23010G16KT 10SM CLR 00/M03 A3016 RMK AO2
KEHY 251428Z AUTO 26018G25KT 10SM CLR 06/M01 A3009 RMK AO2 T00551007
KFKA 251348Z AUTO 05009G15KT 7SM RA SCT010 BKN015 OVC044 10/08 A2977 RMK AO2 LTG DSNT E P0002 T01000075
KCPW 251347Z AUTO 36003KT 10SM CLR 00/M07 A3025 RMK AO2
KFDW 251355Z AUTO 22004KT 10SM CLR 29/15 A3000 RMK AO1
4 changes: 4 additions & 0 deletions exercisefiles/robotframework/robot/libraries/MetarReader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class MetarReader(object):

def __init__(self):
pass
4 changes: 4 additions & 0 deletions exercisefiles/robotframework/robot/metar_test.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*** Settings ***
Library MetarReader

*** Test Cases ***
43 changes: 43 additions & 0 deletions exercisefiles/robotframework/robot/tests/test_metarreader.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import unittest
from metarreader import MetarReader

class TestMetarReader(unittest.TestCase):

def setUp(self):
self.reader = MetarReader()
self.sample_data = [
"SITE1 RA RMK Remark1",
"SITE2 RMK Remark2",
"SITE3"
]
self.reader._add_lines(self.sample_data)

def test_add_data(self):
self.reader.add_data('sample_metar.txt')
self.assertEqual(self.reader.get_number_of_sites(), 3)

def test_get_number_of_sites(self):
self.assertEqual(self.reader.get_number_of_sites(), 3)

def test_site_should_not_exist(self):
with self.assertRaises(AssertionError):
self.reader.site_should_not_exist("SITE1")

def test_site_should_exist(self):
self.reader.site_should_exist("SITE1")
with self.assertRaises(AssertionError):
self.reader.site_should_exist("SITE4")

def test_it_should_rain(self):
self.reader.it_should_rain("SITE1")
with self.assertRaises(AssertionError):
self.reader.it_should_rain("SITE2")

def test_get_remarks(self):
self.assertEqual(self.reader.get_remarks("SITE1"), ["Remark1"])
self.assertEqual(self.reader.get_remarks("SITE2"), ["Remark2"])
with self.assertRaises(AssertionError):
self.reader.get_remarks("SITE3")

if __name__ == '__main__':
unittest.main()

0 comments on commit b501799

Please sign in to comment.