geoalchemy / geoalchemy2

Geospatial extension to SQLAlchemy
http://geoalchemy-2.readthedocs.org
MIT License
640 stars 112 forks source link

Test: Add a container to run the tests #479

Closed mbway closed 1 year ago

mbway commented 1 year ago

Description

in the process of investigating the issue with #478 I had to run the tests, but this was easier said than done as there are a lot of tricky requirements needed to set up an environment where the tests can be run.

To help with this, I set up a docker image that can be built and used to run the tests with tox.

Checklist

This pull request is:

mbway commented 1 year ago

why isn't psycopg2 included in requirements.txt?

adrien-berchet commented 1 year ago

Interesting, thanks!

adrien-berchet commented 1 year ago

Nice work!

I tried to run it locally and I had 2 errors. The first one is when I run ./test_container/build.sh:

➜ ./test_container/build.sh        
[+] Building 0.1s (2/2) FINISHED                                                                                                                                                                    docker:default
 => [internal] load build definition from Dockerfile                                                                                                                                                          0.0s
 => => transferring dockerfile: 2B                                                                                                                                                                            0.0s
 => [internal] load .dockerignore                                                                                                                                                                             0.0s
 => => transferring context: 2B                                                                                                                                                                               0.0s
ERROR: failed to solve: failed to read dockerfile: open /var/lib/docker/tmp/buildkit-mount3630990460/Dockerfile: no such file or directory

I was able to run this script properly by running ./build.sh from the test_container directory. But then I have the following error:

➜ ./test_container/run.sh          
starting postgres
starting mysql
 * Starting MySQL database server mysqld                                                                                                                                                                           su: warning: cannot change directory to /nonexistent: No such file or directory
                                                                                                                                                                                                            [ OK ]
waiting for mysql to start
###############################
GeoAlchemy2 Test Container

run tests with `tox --workdir /output -vv`
###############################
root@e97b7e2cfa5e:/geoalchemy2# tox --workdir /output -vv
using tox.ini: /geoalchemy2/tox.ini (pid 395)
using tox-3.21.4 from /usr/lib/python3/dist-packages/tox/__init__.py (pid 395)
GLOB start: packaging 
GLOB sdist-make: /geoalchemy2/setup.py
[412] /geoalchemy2$ /usr/bin/python3 setup.py sdist --formats=zip --dist-dir /output/dist >../output/log/GLOB-0.log
ERROR: invocation failed (exit code 1), logfile: /output/log/GLOB-0.log
==================================================================================================== log start ====================================================================================================
/usr/lib/python3/dist-packages/setuptools/installer.py:27: SetuptoolsDeprecationWarning: setuptools.installer is deprecated. Requirements should be satisfied by a PEP 517 installer.
  warnings.warn(
Traceback (most recent call last):
  File "/geoalchemy2/setup.py", line 4, in <module>
    setup(
  File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 152, in setup
    _install_setup_requires(attrs)
  File "/usr/lib/python3/dist-packages/setuptools/__init__.py", line 147, in _install_setup_requires
    dist.fetch_build_eggs(dist.setup_requires)
  File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 812, in fetch_build_eggs
    resolved_dists = pkg_resources.working_set.resolve(
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 771, in resolve
    dist = best[req.key] = env.best_match(
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1056, in best_match
    return self.obtain(req, installer)
  File "/usr/lib/python3/dist-packages/pkg_resources/__init__.py", line 1068, in obtain
    return installer(requirement)
  File "/usr/lib/python3/dist-packages/setuptools/dist.py", line 883, in fetch_build_egg
    return fetch_build_egg(self, req)
  File "/usr/lib/python3/dist-packages/setuptools/installer.py", line 87, in fetch_build_egg
    wheel.install_as_egg(dist_location)
  File "/usr/lib/python3/dist-packages/setuptools/wheel.py", line 95, in install_as_egg
    self._install_as_egg(destination_eggdir, zf)
  File "/usr/lib/python3/dist-packages/setuptools/wheel.py", line 103, in _install_as_egg
    self._convert_metadata(zf, destination_eggdir, dist_info, egg_info)
  File "/usr/lib/python3/dist-packages/setuptools/wheel.py", line 124, in _convert_metadata
    os.mkdir(destination_eggdir)
OSError: [Errno 30] Read-only file system: '/geoalchemy2_read_only/.eggs/setuptools_scm-8.0.4-py3.10.egg'

===================================================================================================== log end =====================================================================================================
ERROR: FAIL could not package project - v = InvocationError('/usr/bin/python3 setup.py sdist --formats=zip --dist-dir /output/dist', 1)

Do you know why?

mbway commented 1 year ago
adrien-berchet commented 1 year ago

I also had to rm -rf GeoAlchemy2.egg-info but now it works. Maybe you can add this too in entrypoint.sh? Apart from that everything works well! I just see some warnings from setuptools but I think it's not related to this PR.

adrien-berchet commented 1 year ago

I tested the new version and everything works fine now!

The last improvement I can see is in the TEST.rst: in the current state I think it's not completely clear that we can use either the container or either the actual system. I think we should have one section for the test container (as you wrote it) and another for the system environment which would contain the current 'Install system dependencies', 'Set up the PostGIS database', 'Set the path to the SpatiaLite module', 'Set up the MySQL database' and 'Run Tests' sub sections. So the reader can easily understand which parts applies to the container case and which parts applies for the system case. WDYT?

mbway commented 1 year ago

I can make this change

mbway commented 1 year ago

Are these changes what you were asking for?

adrien-berchet commented 1 year ago

Are these changes what you were asking for?

Yes, exactly, thanks!

adrien-berchet commented 1 year ago

Thank you very much for this work @mbway !!!