rrsg2020 / analysis

4 stars 0 forks source link

Refactor tests #18

Closed mathieuboudreau closed 3 years ago

mathieuboudreau commented 3 years ago

Hi @jvelazquez-reyes,

Thanks for getting a draft of the tests done! I've refactored them into a format such that they are now compatible with the PyTest tool.

I also modified your tests to be more in line with how I wanted to define the behaviour.

To use the tests, you need to install the repo as a package and then run a command. Here are the steps:

pip install -e .
pytest .

Here is the current output:


(rrsg_analysis) mathieuboudreau@mathieu analysis % pytest .                                     
================================================ test session starts =================================================
platform darwin -- Python 3.7.7, pytest-6.2.1, py-1.10.0, pluggy-0.13.1
rootdir: /Users/mathieuboudreau/tmp/analysis
collected 2 items                                                                                                    

test/test_nist.py FF                                                                                           [100%]

====================================================== FAILURES ======================================================
_____________________________________________ TestCore.test_formatArray ______________________________________________

self = <test_nist.TestCore object at 0x7ff207d36d50>

    @pytest.mark.unit
    def test_formatArray(self):
        temperature = 20
        serial_number = 42

        test_array = temperature_correction(temperature, serial_number)

        reference_temperature = get_reference_NIST_values(serial_number)

>       assert np.shape(test_array) == np.shape(reference_temperature)
E       assert (14, 1) == (14,)
E         Left contains one more item: 1
E         Use -v to get the full diff

test/test_nist.py:28: AssertionError
___________________________________________ TestCore.test_inputTemperature ___________________________________________

self = <test_nist.TestCore object at 0x7ff2096f8890>

    @pytest.mark.unit
    def test_inputTemperature(self):
        sphere = 1
        temperature = 20
        serial_number = 42

        test_temperature = temperature_correction(temperature, serial_number)

        reference_temperature = get_reference_NIST_values(serial_number)

>       assert  np.testing.assert_array_equal(test_temperature, reference_temperature)
E       AssertionError: 
E       Arrays are not equal
E       
E       (shapes (14, 1), (14,) mismatch)
E        x: array([[1883.97],
E              [1330.16],
E              [ 987.27],...
E        y: array([1883.97, 1330.16,  987.27,  690.08,  484.97,  341.58,  240.86,
E               174.95,  121.08,   85.75,   60.21,   42.89,   30.4 ,   21.44])

test/test_nist.py:41: AssertionError
================================================== warnings summary ==================================================
test/test_nist.py:19
  /Users/mathieuboudreau/tmp/analysis/test/test_nist.py:19: PytestUnknownMarkWarning: Unknown pytest.mark.unit - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
    @pytest.mark.unit

test/test_nist.py:31
  /Users/mathieuboudreau/tmp/analysis/test/test_nist.py:31: PytestUnknownMarkWarning: Unknown pytest.mark.unit - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
    @pytest.mark.unit

-- Docs: https://docs.pytest.org/en/stable/warnings.html
============================================== short test summary info ===============================================
FAILED test/test_nist.py::TestCore::test_formatArray - assert (14, 1) == (14,)
FAILED test/test_nist.py::TestCore::test_inputTemperature - AssertionError: 
=========================================== 2 failed, 2 warnings in 1.29s ============================================
(rrsg_analysis) mathieuboudreau@mathieu analysis % 

Note that the two tests currently fail. This isn't a problem with the tests, but a problem with the code not acting the way we expect it to behave (i.e. the array outputed by the temperature_correction isn't in the same format as the one outputted by get_reference_NIST_values). Once we merge this PR into your branch (this PR is already setup to do that and not into master), you'll just have to find a way to reformat the array inside temperature_correction at the end so that it matches get_reference_NIST_values and the tests pass.

Let me know if anything isn't clear enough and we can setup a meeting next week to discuss (I'm on vacation this week)

mathieuboudreau commented 3 years ago

@jvelazquez-reyes please test this branch and if it works for you and makes sense, merge it into your branch.

jvelazquez-reyes commented 3 years ago

Hi @mathieuboudreau,

Thank you for refactoring the tests. I noticed that you removed the test (1- testing that if you give an input temperature that is one of the temperatures already in the dictionnary, the value that's the output is exactly the same as the preset one) that you proposed in our other PR discussion. To implement the original test, can I take one of the values from the output of the function get_reference_NIST_values to compare it with our output?

I know exactly where is the source of the assertion error beacause I forced the outputArray to be (14, len(input_temperature)) in size. That is, if input temperature = 20 the output shape is (14,1) and if input_temperature is an N-size array the output is of size (14,N) To get the tests pass, I will reformat our current output to (14,) when input temperature = 20 and I will keep the functionality in case the user pass an array as input_temperature, unless you indicate otherwise.