Skip to content

Commit

Permalink
adding MariaDB testing (pass --tech=2 to msnoise utils test)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasLecocq committed Feb 7, 2024
1 parent e8088c4 commit cf389b3
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
2 changes: 1 addition & 1 deletion msnoise/api.py
Expand Up @@ -2112,7 +2112,7 @@ def xr_create_or_open(fn, taxis=[], name="CCF"):
# failed, the file handle was still open and it failed later.
ds = xr.load_dataset(fn)
return ds
times = pd.date_range("2000-01-01", freq="H", periods=0)
times = pd.date_range("2000-01-01", freq="h", periods=0)
if name == "CCF":
data = np.random.random((len(times), len(taxis)))
dr = xr.DataArray(data, coords=[times, taxis], dims=["times", "taxis"])
Expand Down
8 changes: 8 additions & 0 deletions msnoise/s000installer.py
Expand Up @@ -43,6 +43,7 @@
from sqlalchemy import create_engine
from sqlalchemy.exc import *
from sqlalchemy.orm import sessionmaker
from sqlalchemy_utils import database_exists, create_database
try:
import cPickle
except ImportError:
Expand Down Expand Up @@ -219,6 +220,13 @@ def ask(prompt, default, input_func=raw_input):
engine = create_engine('postgresql+psycopg2://%s:%s@%s/%s'
% (username, password, hostname, database),
echo=False)



if not database_exists(engine.url):
logging.info("Database does not exist. Creating it right away!")
create_database(engine.url)

create_database_inifile(tech, hostname, database, username, password,
prefix)

Expand Down
5 changes: 3 additions & 2 deletions msnoise/scripts/msnoise.py
Expand Up @@ -1504,16 +1504,17 @@ def utils_bugreport(ctx, sys, modules, env, all):

@utils.command(name="test")
@click.option('-p', '--prefix', default="", help='Prefix for tables')
@click.option('--tech', default=1, help='Test using (1) SQLite or (2) MariaDB (you need to start that server before!)')
@click.option('-c', '--content', default=False, is_flag=True)
def utils_test(prefix, content):
def utils_test(prefix, tech, content):
"""Runs the test suite, should be executed in an empty folder!"""
import matplotlib.pyplot as plt
plt.switch_backend("agg")
if not content:
from ..test.tests import main
else:
from ..test.content_tests import main
main(prefix=prefix)
main(prefix=prefix, tech=tech)


@utils.command(name="jupyter")
Expand Down
28 changes: 24 additions & 4 deletions msnoise/test/tests.py
Expand Up @@ -36,8 +36,19 @@ def test_001_S01installer(self):
if "PREFIX" in os.environ:
self.prefix=os.environ["PREFIX"]
try:
ret = main(tech=1, prefix=self.prefix,
filename='testmsnoise.sqlite')
if os.environ["TECH"] == "1":
ret = main(tech=1, prefix=self.prefix,
hostname="localhost",
username="root",
password="SECRET",
database=os.environ["hash"])
elif os.environ["TECH"] == "2":
ret = main(tech=2, prefix=self.prefix,
hostname=os.environ["MARIADB_HOSTNAME"],
username=os.environ["MARIADB_USERNAME"],
password=os.environ["MARIADB_PASSWORD"],
database=os.environ["hash"])

self.failUnlessEqual(ret, 0)
except:
traceback.print_exc()
Expand Down Expand Up @@ -653,24 +664,33 @@ def test_99219_crondays_weeks_days_hours_optional_blank(self):
self.assertEqual(parsed_crondays, datetime.timedelta(days=3*7+4, seconds=12*3600))


def main(prefix=""):
def main(prefix="", tech=1):
import matplotlib.pyplot as plt
plt.switch_backend("agg")

import os
import sys
test_dir = tempfile.mkdtemp(prefix="msnoise_")
os.chdir(test_dir)
print("Tests will be executed in %s" % test_dir)

# c = len(os.listdir(os.getcwd()))
# if c > 0:
# print("Directory is not empty, can't run tests here!")
# sys.exit()
os.environ["PREFIX"] = prefix
os.environ["hash"] = "h" + test_dir[-10:]
os.environ["TECH"] = str(tech)
print("Tests will be executed in %s" % test_dir)
if tech == 2:
print("The database localhost/%s was NOT deleted after this test!" % os.environ["HASH"])

suite = unittest.defaultTestLoader.loadTestsFromTestCase(MSNoiseTests)
runner = unittest.TextTestRunner(verbosity=4)
result = runner.run(suite)

print("Tests executed in %s" % test_dir)
if tech == 2:
print("The database localhost/%s was NOT deleted after this test!" % os.environ["HASH"])
if not result.wasSuccessful():
sys.exit(1)

Expand Down

0 comments on commit cf389b3

Please sign in to comment.