diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..343e8a3 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,57 @@ +# This file contains checks to run unit tests. +# +# Special thank you to pylint-dev project at GitHub where inspiration +# was taken. +name: unit tests + +on: + pull_request: + branches: + - main + push: + +jobs: + tests-linux: + name: run / ${{ matrix.python-version }} / Linux + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10"] + services: + timescale: + image: timescale/timescaledb:latest-pg15 + env: + POSTGRES_PASSWORD: xyzzy + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + + timeout-minutes: 25 + steps: + - uses: actions/checkout@v4.0.0 + - name: Set up Python ${{ matrix.python-version }} + id: python + uses: actions/setup-python@v4.7.0 + with: + python-version: ${{ matrix.python-version }} + check-latest: true + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pytest + if [ -f requirements.txt ]; then + pip install -r requirements.txt + else + echo "No requirements.txt file found" + fi + - name: Run PyTest + env: + PGHOST: localhost + PGUSER: postgres + PGPASSWORD: xyzzy + PGPORT: 5432 + run: python -m pytest diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8f82d3f --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +psycopg2>=2.9.2 diff --git a/src/doctor/rules/compression_test.py b/src/doctor/rules/compression_test.py index be28b43..b74d4a7 100644 --- a/src/doctor/rules/compression_test.py +++ b/src/doctor/rules/compression_test.py @@ -34,11 +34,14 @@ class TestCompressionRules(unittest.TestCase): def setUp(self): """Set up unit tests for compression rules.""" - user = (os.getenv("PGUSER") or os.getlogin()) + user = os.getenv("PGUSER") host = os.getenv("PGHOST") port = os.getenv("PGPORT") or "5432" - dbname = (os.getenv("PGDATABASE") or os.getlogin()) - self.__conn = psycopg2.connect(dbname=dbname, user=user, host=host, port=port, + dbname = os.getenv("PGDATABASE") + password = os.getenv("PGPASSWORD") + print(f"connecting to {host}:{port} database {dbname}") + self.__conn = psycopg2.connect(dbname=dbname, user=user, host=host, + password=password, port=port, cursor_factory=RealDictCursor) table = Hypertable("conditions", "time", { 'time': "timestamptz not null",