Skip to content

Commit

Permalink
Merge pull request TeamCOMPAS#1195 from avivajpeyi/fix_pytest_errors
Browse files Browse the repository at this point in the history
Fix pytest errors
  • Loading branch information
ilyamandel authored Sep 5, 2024
2 parents a885df8 + 74239da commit 4b9ba29
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 290 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/compas-compile-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ name: COMPAS compile test
jobs:
compas:
env:
ARTIFACT_NAME: detailedEvolutionPlot.eps
ARTIFACT_NAME: detailedEvolutionPlot.png
ARTIFACT_PATH: py_tests/test_artifacts

name: Build COMPAS
runs-on: '${{ matrix.os}}'
container: '${{matrix.container}}'
Expand Down Expand Up @@ -49,8 +50,8 @@ jobs:
pip install -e .[dev]
- name: Run example COMPAS job
run: |
export COMPAS_ROOT_DIR=${GITHUB_WORKSPACE}
cd ${GITHUB_WORKSPACE}/misc/examples/methods_paper_plots/detailed_evolution
export COMPAS_EXECUTABLE_PATH=${GITHUB_WORKSPACE}/src/COMPAS
cd ${GITHUB_WORKSPACE}/py_tests/test_data/
chmod 755 run.sh
cat run.sh
./run.sh
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
# #
###################################################################

import os, sys
import os
import shutil
import numpy as np
import h5py as h5
import matplotlib.pyplot as plt
from matplotlib import rcParams
import argparse
import tempfile
from pathlib import Path

HERE = os.path.dirname(os.path.realpath(__file__))
VAN_DEN_HEUVEL_DIR = os.path.join(HERE, '/van_den_heuvel_figures/')
IMG_DIR = Path(__file__).parent / "van_den_heuvel_figures"



Expand Down Expand Up @@ -582,7 +582,7 @@ def getEventImage(self, image_num, rotate_image):
on the stellar types, to get the van den Heuvel diagrams.
"""

self.imgFile = os.path.join(VAN_DEN_HEUVEL_DIR, f'{image_num}.png')
self.imgFile = os.path.join(IMG_DIR, f'{image_num}.png')
img = plt.imread(self.imgFile) # import image
if rotate_image:
img = img[:, ::-1, :] # flip across y-axis
Expand Down
3 changes: 0 additions & 3 deletions examples/methods_paper_plots/detailed_evolution/Grid_demo.txt

This file was deleted.

This file was deleted.

6 changes: 2 additions & 4 deletions py_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

HERE = os.path.dirname(__file__)
TEST_CONFIG_DIR = os.path.join(HERE, "test_data")
TEST_GRID = os.path.join(TEST_CONFIG_DIR, "grid.txt")
TEST_BASH = os.path.join(TEST_CONFIG_DIR, "run.sh")
TEST_ARCHIVE_DIR = os.path.join(HERE, "test_artifacts")
REPO_ROOT = os.getenv("COMPAS_ROOT_DIR", os.path.abspath(os.path.join(HERE, "..")))
COMPAS_EXE = os.path.join(REPO_ROOT, "src", "COMPAS")
Expand All @@ -27,10 +27,8 @@ def example_compas_output_path(clean=False):
if not os.path.exists(compas_data_path) or clean: # Check if path exists
curr_dir = os.getcwd()
os.chdir(TEST_CONFIG_DIR)
cmd = f"{COMPAS_EXE} --detailed-output --grid {TEST_GRID}"
# run the command in shell "compas_run_submit {TEST_CONFIG_FNAME}" with subprocess
subprocess.run(cmd, shell=True, check=True)

subprocess.run(TEST_BASH, shell=True, check=True)
os.chdir(curr_dir)
print("Generated COMPAS test data")

Expand Down
2 changes: 0 additions & 2 deletions py_tests/test_data/grid.txt

This file was deleted.

19 changes: 19 additions & 0 deletions py_tests/test_data/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#bin/bash
echo ">>> GENERATING TEST COMPAS DATA <<<"
# if $COMPAS_EXECUTABLE_PATH not set, set to ../../src/COMPAS
COMPAS_EXECUTABLE_PATH=${COMPAS_EXECUTABLE_PATH:-../../src/COMPAS}
$COMPAS_EXECUTABLE_PATH \
-n 2 \
--initial-mass-1 35 \
--initial-mass-2 31 \
-a 3.5 \
--random-seed 0 \
--metallicity 0.001 \
--detailed-output \
> compas_run.log
cat compas_run.log
echo "Generating detailed evolution plot"
compas_plot_detailed_evolution "./COMPAS_Output/Detailed_Output/BSE_Detailed_Output_0.h5" --dont-show >> detailed_evolution.log
echo "Out files:"
ls -l
echo ">>> DONE <<<"
2 changes: 1 addition & 1 deletion py_tests/test_plot_detailed_evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def test_plotter(example_compas_output_path, capsys, test_archive_dir):

assert runtime < 30
assert os.path.exists(os.path.join(test_archive_dir, "vanDenHeuvelPlot.eps"))
assert os.path.exists(os.path.join(test_archive_dir, "detailedEvolutionPlot.eps"))
assert os.path.exists(os.path.join(test_archive_dir, "detailedEvolutionPlot.png"))

with open(os.path.join(test_archive_dir, "test_plotter.log"), "w") as f:
f.write(sout)

0 comments on commit 4b9ba29

Please sign in to comment.