Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New tests added #82

Closed
wants to merge 11 commits into from
Closed

New tests added #82

wants to merge 11 commits into from

Conversation

ClaudiaLSS
Copy link
Collaborator

No description provided.

@ClaudiaLSS ClaudiaLSS linked an issue Sep 6, 2023 that may be closed by this pull request
43 tasks
@FLomb FLomb requested review from Bachibouzouk and FLomb September 6, 2023 14:02
@Bachibouzouk
Copy link
Collaborator

I see that the branch tests on which this PR is directed is no different than main branch, is that normal @mohammadamint ?

@Bachibouzouk
Copy link
Collaborator

Bachibouzouk commented Sep 6, 2023

To be able to checkout locally @ClaudiaLSS branch I did

git fetch upstream pull/82/head:<whichever name I want to have locally>, in my case this was

git fetch upstream pull/82/head:claudia_tests
followed by
git checkout claudia_tests

We only have read acces unless @ClaudiaLSS grant us write access like described in the docs

Note: 82 is the number of this PR, for a different PR you should change it in the command

Copy link
Collaborator

@Bachibouzouk Bachibouzouk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your efforts @ClaudiaLSS it feels good to have some tests !

I managed to make all test pass (except the tests where maximum_profile is used in the User class).

I made suggestion that you can accept in batch and group into one single commit (from github directly) or in several commits as you wish.

A general comment is to delete the unused import statements (I see them greyed out in pycharm)

I would like also that we start linting the code using black it is a pip package you can install and simply run black tests/ and it lints automatically your files

I would suggest that changes are first made such as to be able to run the tests and that they pass, then we merge and you can improve the tests in a subsequent PR


# Tests that the peak time range is calculated correctly for a single user class with the default peak_enlarge value
def test_single_user_class_default_peak_enlarge(self):
user_list = [User(maximum_profile=np.array([1, 2, 3, 4, 5]))]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

User class does not have argument maximum_profile this leads to an error when I run the tests locally. You probably locally changed the User class and forgot to commit and push this change.

tests/test_peak_time_range.py Outdated Show resolved Hide resolved
def test_calc_peak_time_range_with_inputs(self):
j=1
peak_enlarge=0.15
user_list=load_usecase(j,peak_enlarge )
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
user_list=load_usecase(j,peak_enlarge )
user_list=load_usecase(j)

from ramp.core.initialise import initialise_inputs
from ramp.core.stochastic_process import calc_peak_time_range

def load_usecase(j=None, fname=None):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you reuse the same function several times then define it under tests/utils.py and import it. That way it is easier to maintain the tests on the long term

Comment on lines 9 to 19
import os
import pytest
import numpy as np
import random
import math
from scipy.stats import norm

from ramp.core.core import User, Appliance
from ramp.core.core import UseCase
from ramp.core.initialise import initialise_inputs
from ramp.core.stochastic_process import calc_peak_time_range
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import os
import pytest
import numpy as np
import random
import math
from scipy.stats import norm
from ramp.core.core import User, Appliance
from ramp.core.core import UseCase
from ramp.core.initialise import initialise_inputs
from ramp.core.stochastic_process import calc_peak_time_range
import numpy as np
from ramp.core.initialise import initialise_inputs
from ramp.core.stochastic_process import calc_peak_time_range

In the suggestion I removed the unused imports

def test_single_user_class_default_peak_enlarge(self):
user_list = [User(maximum_profile=np.array([1, 2, 3, 4, 5]))]
peak_time_range = calc_peak_time_range(user_list)
assert isinstance(peak_time_range, np.ndarray)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the return value of calc_peak_time_range is the return of np.arange() function I don't think it makes sense to test for np.ndarray here

Comment on lines 47 to 50
assert isinstance(peak_time_range, np.ndarray)
assert peak_time_range.shape[0] > 0
assert peak_time_range.dtype == int
assert np.all(peak_time_range >= 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those are the same assert than for all the other tests, shouldn't be the test more specific to the change of peak_enlarge value in this case?

@@ -0,0 +1,39 @@
#!/usr/bin/env python3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this test different than test_calc_peak_time_range.py::test_calc_peak_time_range_with_inputs ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the review! I think the file [test_peak_time_range.py] was not supposed to be there, the real one was calc_peak_time_range.py. The first one needs to be deleted, sorry!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problems, this is what reviews are for :)


#Tests that the method returns a value greater than func_cycle
@pytest.mark.usefixtures("appliance_instance")
def test_rand_time_equal_or_greater_than_func_cycle(self, appliance_instance):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for such random function the test should run on at least 100 iteration of the method and make sure for none of these call is the rand_time < func_cycle

ClaudiaLSS and others added 3 commits October 3, 2023 15:41
- test focused on peak time range values added.
- at least 100 iteration of the method added to make sure none of these gives rand_time < func_cycle
- new tests for switch on coincidence added
@ClaudiaLSS ClaudiaLSS marked this pull request as ready for review October 4, 2023 01:58
@Bachibouzouk
Copy link
Collaborator

The failing doc is being tackled in #85 and is due to deprecated config files, this should not impact this PR :)

@FLomb
Copy link
Contributor

FLomb commented Oct 23, 2023

I have just approved #85; should we rebase the RAMP-project:tests branch to be up-to-date with the fix? And check if that solves the problem with the failing doc? @Bachibouzouk you are the one who can do this best :)

@Bachibouzouk
Copy link
Collaborator

Bachibouzouk commented Oct 24, 2023

I have just approved #85; should we rebase the RAMP-project:tests branch to be up-to-date with the fix? And check if that solves the problem with the failing doc? @Bachibouzouk you are the one who can do this best :)

Maybe @ClaudiaLSS can simply merge development into her branch and we merge dev into RAMP-project:tests because it is easier. Then we would rebase RAMP-project:tests on development before merging it into development

@Bachibouzouk
Copy link
Collaborator

@ClaudiaLSS - what is your stand on this PR?

@ClaudiaLSS
Copy link
Collaborator Author

Maybe @ClaudiaLSS can simply merge development into her branch and we merge dev into RAMP-project:tests because it is easier. Then we would rebase RAMP-project:tests on development before merging it into development

Hi @Bachibouzouk ! I'll try this.

@ClaudiaLSS
Copy link
Collaborator Author

Hi @Bachibouzouk! I think now dev and test branches are identical. I still don't have much experience with this but can you see if everything is ok?
Thanks!

@Bachibouzouk
Copy link
Collaborator

@ClaudiaLSS - you merged main instead of developement, I think the easier is that I will revert your last commit and then we merge your branch into test

@Bachibouzouk
Copy link
Collaborator

This PR is continued in #93

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add more tests/checks in RAMP
3 participants