From 8fc9f049bb8f90e2c04f2385765c5ea8fabfbfff Mon Sep 17 00:00:00 2001 From: GamzeUnlu95 Date: Wed, 13 Nov 2019 10:58:32 +0100 Subject: [PATCH 1/2] ixmp tests test_check_year() and test_ispanda() are added. --- tests/test_check_year.py | 38 ++++++++++++++++++++++++++++++++++++++ tests/test_utils.py | 8 ++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/test_check_year.py diff --git a/tests/test_check_year.py b/tests/test_check_year.py new file mode 100644 index 000000000..1b26bf775 --- /dev/null +++ b/tests/test_check_year.py @@ -0,0 +1,38 @@ +""" +Test check_year(y,s) + +@author: unlu +""" +from ixmp.utils import check_year +import pytest + +"Enter a string value for y to raise a ValueError. - in this case test should be successfull" + +def test_check_year(): + + y1= "a" + s1= "a" + + with pytest.raises(ValueError): + assert check_year(y1,s1) + + + "If y = None." + + y2 = None + s2 = None + + assert check_year(y2,s2) == None + + "If y is integer." + + y3= 4 + s3= 4 + + assert check_year(y3,s3) == True + + + + + + diff --git a/tests/test_utils.py b/tests/test_utils.py index 5a1f8e52a..e497b9d8b 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -41,6 +41,14 @@ def test_pd_io_xlsx_multi(): _obs = obs[k] pdt.assert_frame_equal(_obs, _exp) +def test_ispanda(): + + fname = 'test.csv' + data_frame = [1,2,3,4] + + with pytest.raises(ValueError): + assert utils.pd_write(data_frame, fname) + m_s = dict(model='m', scenario='s') From d6316330ff76537af92555ed89adc78e6c7a60c6 Mon Sep 17 00:00:00 2001 From: GamzeUnlu95 Date: Mon, 18 Nov 2019 15:27:41 +0100 Subject: [PATCH 2/2] Revision of the tests and changes to code format/structure - Moved test_check_year to test_utils.py. - Added tmp_path to test_pd_write. - Adjsuted code structure according to PEP 8. --- tests/test_check_year.py | 38 -------------------------------------- tests/test_utils.py | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 32 insertions(+), 42 deletions(-) delete mode 100644 tests/test_check_year.py diff --git a/tests/test_check_year.py b/tests/test_check_year.py deleted file mode 100644 index 1b26bf775..000000000 --- a/tests/test_check_year.py +++ /dev/null @@ -1,38 +0,0 @@ -""" -Test check_year(y,s) - -@author: unlu -""" -from ixmp.utils import check_year -import pytest - -"Enter a string value for y to raise a ValueError. - in this case test should be successfull" - -def test_check_year(): - - y1= "a" - s1= "a" - - with pytest.raises(ValueError): - assert check_year(y1,s1) - - - "If y = None." - - y2 = None - s2 = None - - assert check_year(y2,s2) == None - - "If y is integer." - - y3= 4 - s3= 4 - - assert check_year(y3,s3) == True - - - - - - diff --git a/tests/test_utils.py b/tests/test_utils.py index e497b9d8b..3c6a7c805 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -41,15 +41,43 @@ def test_pd_io_xlsx_multi(): _obs = obs[k] pdt.assert_frame_equal(_obs, _exp) -def test_ispanda(): - + +def test_pd_write(tmp_path): + fname = 'test.csv' - data_frame = [1,2,3,4] - + d = tmp_path / "sub" + d.mkdir() + + data_frame = [1, 2, 3, 4] + with pytest.raises(ValueError): assert utils.pd_write(data_frame, fname) +def test_check_year(): + + # If y is a string value, raise a Value Error. + + y1 = "a" + s1 = "a" + with pytest.raises(ValueError): + assert utils.check_year(y1, s1) + + # If y = None. + + y2 = None + s2 = None + + assert utils.check_year(y2, s2) is None + + # If y is integer. + + y3 = 4 + s3 = 4 + + assert utils.check_year(y3, s3) is True + + m_s = dict(model='m', scenario='s') URLS = [