Skip to content

Commit

Permalink
Disable Django-related test on Py2.
Browse files Browse the repository at this point in the history
  • Loading branch information
idlesign committed Dec 28, 2018
1 parent ef1f4ed commit 839e1fa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 17 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def get_readme():
test_suite='tests',
tests_require=[
'pytest',
'django',
'pytest-stub',
],

classifiers=[
Expand Down
42 changes: 26 additions & 16 deletions tests/contrib/test_django.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
import os
from sys import version_info

import pytest

PY2 = (version_info[0] == 2)


@pytest.fixture
def patch_project_dir(monkeypatch):
monkeypatch.setattr('uwsgiconf.contrib.django.uwsgify.toolbox.find_project_dir', lambda: 'dummy')


@pytest.fixture
def patch_base_command(monkeypatch, patch_project_dir, tmpdir):
def patch_base_command(monkeypatch, patch_project_dir, tmpdir, stub):

class Settings(object):

configured = True
DEBUG = False
STATIC_ROOT = '/static/'

class Command(object):
pass

class Error(Exception):
pass

monkeypatch.setattr('django.conf.settings', Settings)
monkeypatch.setattr('django.core.management.base.BaseCommand', Command)
monkeypatch.setattr('django.core.management.base.CommandError', Error)
stub.apply({
'django.core.management.base': {
'CommandError': Error,
'BaseCommand': '[cls]',
},
'django.conf.settings': Settings,
})

fifofile = tmpdir.join('some.fifo')
fifofile.write('')
Expand All @@ -34,10 +39,8 @@ class Error(Exception):
lambda project_name: '%s' % fifofile)


def test_uwsgi_run(monkeypatch, patch_project_dir):

def exec(cmd, args):
pass
@pytest.mark.skipif(PY2, reason='Not tested on PY2')
def test_uwsgi_run(monkeypatch, patch_project_dir, stub):

class Settings(object):

Expand All @@ -46,42 +49,48 @@ class Settings(object):
STATIC_URL = '/static/'
STATIC_ROOT = '/dummy/static/'

def call_command(*args, **kwargs):
return
stub.apply({
'django.core.management.call_command': '[func]',
'django.core.management.base.BaseCommand': '[cls]',
'django.conf.settings': Settings,
})

monkeypatch.setattr('django.core.management.call_command', call_command)
monkeypatch.setattr('django.conf.settings', Settings)
monkeypatch.setattr('os.execvp', exec)
monkeypatch.setattr('os.execvp', lambda *args, **kwargs: None)

from uwsgiconf.contrib.django.uwsgify.management.commands.uwsgi_run import Command

Command().handle(compile=False, use_static_handler=True)


@pytest.mark.skipif(PY2, reason='Not tested on PY2')
def test_uwsgi_log(patch_base_command):
from uwsgiconf.contrib.django.uwsgify.management.commands.uwsgi_log import Command

Command().handle(reopen=True, rotate=False)


@pytest.mark.skipif(PY2, reason='Not tested on PY2')
def test_uwsgi_reload(patch_base_command):
from uwsgiconf.contrib.django.uwsgify.management.commands.uwsgi_reload import Command

Command().handle(force=False, workers=False, chain=False)


@pytest.mark.skipif(PY2, reason='Not tested on PY2')
def test_uwsgi_stats(patch_base_command):
from uwsgiconf.contrib.django.uwsgify.management.commands.uwsgi_stats import Command

Command().handle()


@pytest.mark.skipif(PY2, reason='Not tested on PY2')
def test_uwsgi_stop(patch_base_command):
from uwsgiconf.contrib.django.uwsgify.management.commands.uwsgi_stop import Command

Command().handle(force=False)


@pytest.mark.skipif(PY2, reason='Not tested on PY2')
def test_uwsgi_sysinit_systemd(patch_base_command, capsys):
from uwsgiconf.contrib.django.uwsgify.management.commands.uwsgi_sysinit import Command

Expand All @@ -97,6 +106,7 @@ def test_uwsgi_sysinit_systemd(patch_base_command, capsys):
assert 'dummy/manage.py uwsgi_run' in out


@pytest.mark.skipif(PY2, reason='Not tested on PY2')
def test_uwsgi_sysinit_upstart(patch_base_command, capsys):
from uwsgiconf.contrib.django.uwsgify.management.commands.uwsgi_sysinit import Command

Expand Down

0 comments on commit 839e1fa

Please sign in to comment.