diff --git a/exercisefiles/robotframework/README.md b/exercisefiles/robotframework/README.md new file mode 100644 index 0000000..22bd831 --- /dev/null +++ b/exercisefiles/robotframework/README.md @@ -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. diff --git a/exercisefiles/robotframework/data/metar_data.txt b/exercisefiles/robotframework/data/metar_data.txt new file mode 100644 index 0000000..8cba232 --- /dev/null +++ b/exercisefiles/robotframework/data/metar_data.txt @@ -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 \ No newline at end of file diff --git a/exercisefiles/robotframework/robot/libraries/MetarReader.py b/exercisefiles/robotframework/robot/libraries/MetarReader.py new file mode 100644 index 0000000..22e1229 --- /dev/null +++ b/exercisefiles/robotframework/robot/libraries/MetarReader.py @@ -0,0 +1,4 @@ +class MetarReader(object): + + def __init__(self): + pass diff --git a/exercisefiles/robotframework/robot/metar_test.robot b/exercisefiles/robotframework/robot/metar_test.robot new file mode 100644 index 0000000..d881cdc --- /dev/null +++ b/exercisefiles/robotframework/robot/metar_test.robot @@ -0,0 +1,4 @@ +*** Settings *** +Library MetarReader + +*** Test Cases *** diff --git a/exercisefiles/robotframework/robot/tests/test_metarreader.py b/exercisefiles/robotframework/robot/tests/test_metarreader.py new file mode 100644 index 0000000..9a5d181 --- /dev/null +++ b/exercisefiles/robotframework/robot/tests/test_metarreader.py @@ -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()