From aceaef4a7a998fccef468be5035e966358addc29 Mon Sep 17 00:00:00 2001
From: Bastien Abadie <bastien@nextcairn.com>
Date: Mon, 7 May 2018 16:46:11 +0200
Subject: [PATCH] Split test/build requirements

---
 .gitignore                   |  1 +
 .gitlab-ci.yml               |  7 +++----
 arkindex/project/runtests.py | 22 ++++++++++++++++++++++
 requirements.txt             |  5 -----
 setup.py                     |  9 +++++++++
 tests-requirements.txt       |  2 ++
 6 files changed, 37 insertions(+), 9 deletions(-)
 create mode 100644 arkindex/project/runtests.py
 create mode 100644 tests-requirements.txt

diff --git a/.gitignore b/.gitignore
index 37784224e7..b3eb314b78 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,3 +4,4 @@ playbook.retry
 *.egg-info
 build
 dist
+.eggs
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 14afa3a364..a7801193d4 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -19,10 +19,9 @@ backend-tests:
     DB_PORT: 5432
 
   before_script:
-    - apk update
-    - apk add postgresql-dev libjpeg-turbo-dev gcc musl-dev
-    - pip install -r requirements.txt
+    - apk --update add postgresql-dev libjpeg-turbo-dev gcc musl-dev
 
   script:
+    - python setup.py test
+    - pip install .[test]
     - flake8
-    - cd arkindex && ./manage.py test
diff --git a/arkindex/project/runtests.py b/arkindex/project/runtests.py
new file mode 100644
index 0000000000..bf4147a422
--- /dev/null
+++ b/arkindex/project/runtests.py
@@ -0,0 +1,22 @@
+#This file exists to allow python setup.py test to work.
+import os, sys
+os.environ['DJANGO_SETTINGS_MODULE'] = 'arkindex.project.settings'
+test_dir = os.path.dirname(__file__)
+sys.path.insert(0, test_dir)
+
+from django.test.utils import get_runner
+from django.conf import settings
+
+def run():
+    # Setup django
+    import django
+    django.setup()
+
+    # Run tests on documents
+    TestRunner = get_runner(settings)
+    test_runner = TestRunner(verbosity=2, interactive=True)
+    failures = test_runner.run_tests(['arkindex.documents.tests'])
+    sys.exit(failures)
+
+if __name__ == '__main__':
+    run()
diff --git a/requirements.txt b/requirements.txt
index d1d6ebfc06..ca6a985a2a 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -6,19 +6,14 @@ django-webpack-loader==0.5.0
 djangorestframework==3.7.1
 elasticsearch==5.4.0
 et-xmlfile==1.0.1
-flake8==3.5.0
 idna==2.6
 ijson==2.3
 jdcal==1.3
-mccabe==0.6.1
 olefile==0.44
 openpyxl==2.4.9
 Pillow==4.3.0
 psycopg2==2.7.3.2
-pycodestyle==2.3.1
-pyflakes==1.6.0
 pytz==2017.2
 requests==2.18.4
 roman==2.0.0
-tripoli==2.0.0
 urllib3==1.22
diff --git a/setup.py b/setup.py
index 775e1a8dd2..8e0f08670b 100644
--- a/setup.py
+++ b/setup.py
@@ -7,6 +7,9 @@ with open('VERSION') as f:
 with open('requirements.txt') as f:
     requirements = f.read().splitlines()
 
+with open('tests-requirements.txt') as f:
+    tests_requirements = f.read().splitlines()
+
 setup(
     name='arkindex',
     version=VERSION,
@@ -15,7 +18,13 @@ setup(
     author_email='abadie@teklia.com',
     url='https://arkindex.teklia.com',
     install_requires=requirements,
+    test_suite='arkindex.project.runtests.run',
+    tests_require=tests_requirements,
+    extras_require={
+        'test': tests_requirements,
+    },
     packages=find_packages(),
+    py_modules=['arkindex',],
     scripts=[
         'arkindex/manage.py',
     ],
diff --git a/tests-requirements.txt b/tests-requirements.txt
new file mode 100644
index 0000000000..891bc2c834
--- /dev/null
+++ b/tests-requirements.txt
@@ -0,0 +1,2 @@
+flake8
+tripoli
-- 
GitLab