Skip to content

Commit

Permalink
Fix unused imports in tests, add CI workflow to run tests
Browse files Browse the repository at this point in the history
  • Loading branch information
GarethCabournDavies committed Jan 8, 2025
1 parent e8e7f04 commit f9b672c
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 33 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/check_code.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: Flake8 check
on: [pull_request]
jobs:
flake8 unused imports:
runs-on: ubuntu-latest
steps:
- name: Install flake8
run: pip install flake8
- name: Checking executables for unused imports
run: flake8 --select=F401 `find bin -type f`
- name: Checking modules for unused imports
run: flake8 --select=F401 `find pycbc | grep '\.py$' | grep -v -e __init__ -e "version.py"`
- name: Checking tests for unused imports
run: flake8 --select=F401 `find test | grep '\.py$' | grep -v test_schemes`

3 changes: 0 additions & 3 deletions test/fft_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,7 @@
import pycbc.fft
from pycbc.fft.backend_support import set_backend
import unittest
import sys
from utils import parse_args_all_schemes, simple_exit
from lal import LIGOTimeGPS as LTG
import lal as _lal

# Because we run many similar tests where we only vary dtypes, precisions,
# or Array/TimeSeries/FrequencySeries, it is helpful to define the following
Expand Down
3 changes: 0 additions & 3 deletions test/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@
'''


import pycbc
import unittest
import itertools
from pycbc.types import *
from pycbc.scheme import *
import numpy
from utils import array_base, parse_args_all_schemes, simple_exit
import sys
import os
import tempfile

Expand Down
1 change: 0 additions & 1 deletion test/test_autochisq.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from math import cos, sin, pi, exp
import unittest
from utils import parse_args_all_schemes, simple_exit
import time

_scheme, _context = parse_args_all_schemes("Auto Chi-squared Veto")

Expand Down
22 changes: 10 additions & 12 deletions test/test_coordinates_space.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,9 @@ def test_polarization(self):
used in the calculation.
"""
from pycbc.waveform import get_fd_det_waveform
from pycbc.coordinates.space import (ssb_to_lisa, lisa_to_ssb,
ssb_to_geo, lisa_to_geo)

from pycbc.types.frequencyseries import FrequencySeries
from pycbc.detector import (Detector, load_detector_config,
add_detector_on_earth,
_ground_detectors)
from pycbc.waveform import get_td_waveform, get_fd_waveform

from pycbc.detector import Detector, add_detector_on_earth,
from pycbc.waveform import get_td_waveform
import importlib

def is_module_installed(module_name):
Expand Down Expand Up @@ -260,7 +255,7 @@ def strain_generator(det='D1', model='IMRPhenomD', fs=4096, df=None,
0, 2*numpy.pi, endpoint=False, num=nx):
params['tc'], params['eclipticlongitude'], \
params['eclipticlatitude'], params['polarization'] = \
lisa_to_ssb(t_lisa, 0, numpy.pi/4,
space.lisa_to_ssb(t_lisa, 0, numpy.pi/4,
polarization_lisa, params['t_offset'])

nparams = {'mass1':params['mass1'], 'mass2':params['mass2'],
Expand All @@ -283,9 +278,12 @@ def strain_generator(det='D1', model='IMRPhenomD', fs=4096, df=None,
'LISA_Z':lisa_Z_fd}

t_geo, ra, dec, polarization_geo = \
ssb_to_geo(params['tc'], params['eclipticlongitude'],
params['eclipticlatitude'],
params['polarization'])
space.ssb_to_geo(
params['tc'],
params['eclipticlongitude'],
params['eclipticlatitude'],
params['polarization']
)

params_3g = params.copy()
params_3g['tc'] = t_geo
Expand Down
2 changes: 0 additions & 2 deletions test/test_frequencyseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,11 @@
These are the unittests for the pycbc frequencyseries type
'''

import pycbc
import unittest
from pycbc.types import *
from pycbc.scheme import *
import numpy
import lal
import sys
import os
import tempfile
from utils import array_base, parse_args_all_schemes, simple_exit
Expand Down
9 changes: 3 additions & 6 deletions test/test_live_coinc_compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,10 @@
import unittest
from types import SimpleNamespace
import numpy as np
# Some duplicate imports, but I want to copy code without changing it!
import numpy, logging, pycbc.pnutils, pycbc.conversions, copy, lal
import cProfile
import logging
from astropy.utils.data import download_file
from pycbc import gps_now
from pycbc.events.coinc import LiveCoincTimeslideBackgroundEstimator as Coincer
import pycbc.events.coinc
from utils import simple_exit
import validation_code.old_coinc as old_coinc

Expand Down Expand Up @@ -145,7 +142,7 @@ def assess_same_output(newout, oldout):
if type(newout[key]) is np.ndarray:
self.assertTrue(len(newout[key]) == len(oldout[key]))
self.assertTrue(
numpy.isclose(newout[key], oldout[key]).all()
np.isclose(newout[key], oldout[key]).all()
)
else:
self.assertTrue(newout[key] == oldout[key])
Expand All @@ -161,7 +158,7 @@ def assess_same_output(newout, oldout):
new_coincer = self.new_coincer
old_coincer = self.old_coincer
self.assertTrue(len(new_coincer.coincs.data) == len(old_coincer.coincs.data))
self.assertTrue(numpy.isclose(new_coincer.coincs.data, old_coincer.coincs.data, rtol=1e-06).all())
self.assertTrue(np.isclose(new_coincer.coincs.data, old_coincer.coincs.data, rtol=1e-06).all())

for ifo in new_coincer.singles:
lgc = True
Expand Down
5 changes: 1 addition & 4 deletions test/test_schemes.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,10 @@
We do not specifically test that the lalwrapped functions raise exceptions from the
GPU, because that test is done in the test_lalwrap unit tests.
'''
import pycbc
import unittest
from pycbc.types import *
from pycbc.scheme import *
import numpy
from numpy import dtype, float32, float64, complex64, complex128
import lal
from numpy import float32, float64, complex64, complex128
from utils import parse_args_all_schemes, simple_exit

_scheme, _context = parse_args_all_schemes("Scheme")
Expand Down
2 changes: 0 additions & 2 deletions test/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@
These are the unittests for the pycbc timeseries type
'''

import pycbc
import unittest
from pycbc.types import *
from pycbc.scheme import *
import numpy
import lal
from utils import array_base, parse_args_all_schemes, simple_exit
import sys
import os
import tempfile

Expand Down

0 comments on commit f9b672c

Please sign in to comment.