-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #129 from NCAR/127-pep8
Auto format python code using pep8
- Loading branch information
Showing
4 changed files
with
105 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
name: Pep8 | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
autopep8: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: autopep8 | ||
uses: peter-evans/autopep8@v2 | ||
with: | ||
args: --recursive --in-place --aggressive --aggressive . | ||
|
||
- name: Check for changes | ||
id: check-changes | ||
run: git diff --exit-code | ||
continue-on-error: true | ||
|
||
- name: Commit and push changes | ||
# a failue of this step means changes were detected | ||
if: steps.check-changes.outcome != 'success' | ||
run: | | ||
git config --global user.name "GitHub Actions" | ||
git config --global user.email "[email protected]" | ||
git commit -am "Auto-format code using Clang-Format" || echo "No changes to commit" | ||
- name: Push changes to main-autopep8 branch | ||
if: steps.check-changes.outcome != 'success' | ||
run: git push origin HEAD:main-autopep8 | ||
|
||
- name: Create Pull Request | ||
if: steps.check-changes.outcome != 'success' | ||
uses: peter-evans/create-pull-request@v6 | ||
with: | ||
token: ${{ secrets.GITHUB_TOKEN }} | ||
commit-message: "Auto-format code using autopep8" | ||
title: "Auto-format code by autopep8" | ||
body: "This is an auto-generated PR with fixes by autopep8." | ||
branch: main-autopep8 |
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 |
---|---|---|
@@ -1,38 +1,50 @@ | ||
import unittest | ||
import musica | ||
|
||
|
||
class TestChapman(unittest.TestCase): | ||
def test_micm_solve(self): | ||
time_step = 200.0 | ||
temperature = 272.5 | ||
pressure = 101253.3 | ||
concentrations = [0.75, 0.4, 0.8, 0.01, 0.02] | ||
|
||
solver = musica.create_micm("configs/chapman") | ||
solver = musica.create_micm("configs/chapman") | ||
rate_constant_ordering = musica.user_defined_reaction_rates(solver) | ||
ordering = musica.species_ordering(solver) | ||
|
||
rate_constants = { | ||
"PHOTO.R1" : 2.42e-17, | ||
"PHOTO.R3" : 1.15e-5, | ||
"PHOTO.R5" : 6.61e-9 | ||
"PHOTO.R1": 2.42e-17, | ||
"PHOTO.R3": 1.15e-5, | ||
"PHOTO.R5": 6.61e-9 | ||
} | ||
|
||
ordered_rate_constants = len(rate_constants.keys()) * [0.0] | ||
|
||
for key, value in rate_constants.items(): | ||
ordered_rate_constants[rate_constant_ordering[key]] = value | ||
|
||
musica.micm_solve(solver, time_step, temperature, pressure, concentrations, ordered_rate_constants) | ||
|
||
self.assertEqual(ordering, {'M': 0, 'O': 2, 'O1D': 1, 'O2': 3, 'O3': 4}) | ||
self.assertEqual(rate_constant_ordering, {'PHOTO.R1': 0, 'PHOTO.R3': 1, 'PHOTO.R5': 2}) | ||
musica.micm_solve( | ||
solver, | ||
time_step, | ||
temperature, | ||
pressure, | ||
concentrations, | ||
ordered_rate_constants) | ||
|
||
self.assertEqual( | ||
ordering, { | ||
'M': 0, 'O': 2, 'O1D': 1, 'O2': 3, 'O3': 4}) | ||
self.assertEqual( | ||
rate_constant_ordering, { | ||
'PHOTO.R1': 0, 'PHOTO.R3': 1, 'PHOTO.R5': 2}) | ||
|
||
self.assertEqual(concentrations[0], 0.75) | ||
self.assertNotEqual(concentrations[1], 0.4) | ||
self.assertNotEqual(concentrations[2], 0.8) | ||
self.assertNotEqual(concentrations[3], 0.01) | ||
self.assertNotEqual(concentrations[4], 0.02) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() | ||
unittest.main() |