diff --git a/msnoise/api.py b/msnoise/api.py index 0a7c6222..aba1f495 100644 --- a/msnoise/api.py +++ b/msnoise/api.py @@ -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"]) diff --git a/msnoise/s000installer.py b/msnoise/s000installer.py index 12cd32b5..c7720048 100644 --- a/msnoise/s000installer.py +++ b/msnoise/s000installer.py @@ -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: @@ -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) diff --git a/msnoise/scripts/msnoise.py b/msnoise/scripts/msnoise.py index 6bbbe963..5066808f 100644 --- a/msnoise/scripts/msnoise.py +++ b/msnoise/scripts/msnoise.py @@ -1504,8 +1504,9 @@ 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") @@ -1513,7 +1514,7 @@ def utils_test(prefix, 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") diff --git a/msnoise/test/tests.py b/msnoise/test/tests.py index 2613738e..c20640a5 100644 --- a/msnoise/test/tests.py +++ b/msnoise/test/tests.py @@ -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() @@ -653,7 +664,7 @@ 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") @@ -661,16 +672,25 @@ def main(prefix=""): 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)