-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[test]: Adding tests to get projection handler
- Loading branch information
Showing
6 changed files
with
156 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
""" | ||
Test get projections handler | ||
""" | ||
from unittest.mock import patch | ||
from minushalf.io import MinushalfYaml | ||
from minushalf.softwares import Vasp | ||
from minushalf.handlers import GetBandProjections | ||
from minushalf.utils import BandStructure | ||
|
||
|
||
def test_get_valence_projections(file_path): | ||
""" | ||
Get projections of GaN 3d | ||
""" | ||
## Variables | ||
minushalf_yaml = MinushalfYaml.from_file() | ||
minushalf_yaml.correction.correction_code = "vc" | ||
software_module = Vasp() | ||
request = { | ||
"minushalf_yaml": minushalf_yaml, | ||
"software_module": software_module, | ||
} | ||
band_structure = BandStructure.create(software_module, | ||
file_path("/gan-3d/")) | ||
|
||
## Mock method in class BandStructure | ||
with patch('minushalf.utils.BandStructure.create') as mock: | ||
mock.return_value = band_structure | ||
handler = GetBandProjections() | ||
response = handler.action(request) | ||
|
||
## Assertions | ||
assert response["projections"]["valence"]["d"]["Ga"] == 16 | ||
assert response["projections"]["conduction"]["s"]["N"] == 56 | ||
assert "projections" in response | ||
|
||
|
||
def test_get_conduction_and_valence_projections(file_path): | ||
""" | ||
Get projections of GaN 3d | ||
""" | ||
## Variables | ||
minushalf_yaml = MinushalfYaml.from_file() | ||
software_module = Vasp() | ||
request = { | ||
"minushalf_yaml": minushalf_yaml, | ||
"software_module": software_module, | ||
} | ||
band_structure = BandStructure.create(software_module, | ||
file_path("/gan-3d/")) | ||
|
||
## Mock method in class BandStructure | ||
with patch('minushalf.utils.BandStructure.create') as mock: | ||
mock.return_value = band_structure | ||
handler = GetBandProjections() | ||
response = handler.action(request) | ||
|
||
## Assertions | ||
assert response["projections"]["valence"]["d"]["Ga"] == 16 | ||
assert response["projections"]["valence"]["p"]["N"] == 78 | ||
assert "projections" in response | ||
|
||
|
||
def test_get_projections_with_ovewrite(file_path): | ||
""" | ||
Get overwrited projections of GaN 3d | ||
""" | ||
## Variables | ||
minushalf_yaml = MinushalfYaml.from_file( | ||
file_path("/minushalf_yaml/minushalf_filled_out.yaml")) | ||
software_module = Vasp() | ||
request = { | ||
"minushalf_yaml": minushalf_yaml, | ||
"software_module": software_module, | ||
} | ||
band_structure = BandStructure.create(software_module, | ||
file_path("/gan-3d/")) | ||
|
||
## Mock method in class BandStructure | ||
with patch('minushalf.utils.BandStructure.create') as mock: | ||
mock.return_value = band_structure | ||
handler = GetBandProjections() | ||
response = handler.action(request) | ||
print(response["projections"]) | ||
## Assertions | ||
assert response["projections"]["valence"]["d"]["Ga"] == 98 | ||
assert "projections" in response | ||
assert "valence" in response["projections"] | ||
assert ("conduction" in response["projections"]) == False |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters