Skip to content

Commit

Permalink
Python2.7 backports for test.support
Browse files Browse the repository at this point in the history
  • Loading branch information
bjester committed Sep 11, 2023
1 parent 2217f6b commit 6c733df
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 9 deletions.
10 changes: 10 additions & 0 deletions tests/testapp/tests/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
try:
# In the Python 2.7 GH workflows, we have to install backported version
from backports.test.support import EnvironmentVarGuard # noqa F401
except ImportError:
try:
# For python >2.7 and <3.10
from test.support import EnvironmentVarGuard # noqa F401
except ImportError:
# In Python 3.10, this has been moved to test.support.os_helper
from test.support.os_helper import EnvironmentVarGuard # noqa F401
2 changes: 1 addition & 1 deletion tests/testapp/tests/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""
import json
import uuid
from test.support import EnvironmentVarGuard

import factory
import mock
Expand All @@ -18,6 +17,7 @@
from facility_profile.models import MyUser
from facility_profile.models import SummaryLog

from .compat import EnvironmentVarGuard
from morango.api.serializers import BufferSerializer
from morango.models.core import AbstractStore
from morango.models.core import Buffer
Expand Down
2 changes: 1 addition & 1 deletion tests/testapp/tests/integration/test_syncsession.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import contextlib
import json
from test.support import EnvironmentVarGuard

import mock
import pytest
Expand All @@ -12,6 +11,7 @@
from facility_profile.models import SummaryLog
from requests.exceptions import Timeout

from ..compat import EnvironmentVarGuard
from morango.errors import MorangoError
from morango.models.certificates import Certificate
from morango.models.certificates import Filter
Expand Down
2 changes: 1 addition & 1 deletion tests/testapp/tests/sync/test_controller.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import contextlib
import json
import uuid
from test.support import EnvironmentVarGuard

import factory
import mock
Expand All @@ -12,6 +11,7 @@
from facility_profile.models import MyUser
from facility_profile.models import SummaryLog

from ..compat import EnvironmentVarGuard
from ..helpers import serialized_facility_factory
from ..helpers import TestSessionContext
from morango.constants import transfer_stages
Expand Down
2 changes: 1 addition & 1 deletion tests/testapp/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
import sys
import uuid
from test.support import EnvironmentVarGuard

from django.db import connection
from django.test.utils import CaptureQueriesContext
Expand All @@ -13,6 +12,7 @@
from facility_profile.models import MyUser
from rest_framework.test import APITestCase as BaseTestCase

from .compat import EnvironmentVarGuard
from morango.api.serializers import BufferSerializer
from morango.api.serializers import CertificateSerializer
from morango.api.serializers import InstanceIDSerializer
Expand Down
9 changes: 4 additions & 5 deletions tests/testapp/tests/test_uuid_utilities.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import hashlib
import mock
import sys
import uuid

import mock
from django.test import TestCase
from facility_profile.models import Facility
from facility_profile.models import InteractionLog
from facility_profile.models import MyUser
from test.support import EnvironmentVarGuard

from .compat import EnvironmentVarGuard
from morango.errors import InvalidMorangoSourceId
from morango.models.core import DatabaseIDModel
from morango.models.core import InstanceIDModel
Expand Down Expand Up @@ -157,9 +157,9 @@ def test_consistent_0_5_instance_id(self, *args):
env["MORANGO_SYSTEM_ID"] = "magicsysid"

DatabaseIDModel.objects.all().update(current=False)
database_id = DatabaseIDModel.objects.create(
DatabaseIDModel.objects.create(
id="7fe445b75cea11858c00fb97bdee8878", current=True
).id
)

self.assertEqual(get_0_5_system_id(), "54940f560a55bbf7d86b")
self.assertEqual(get_0_5_mac_address(), "804f4c20d3b2b5a29b95")
Expand Down Expand Up @@ -197,7 +197,6 @@ def test_envvar_overrides(self, *args):

self.assertEqual(instance.id, expected_id)


@mock.patch(
"ifcfg.interfaces",
return_value={"eth0": {"device": "eth0", "ether": "a0:aa:aa:aa:aa"}},
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ deps =
cryptography1.2: cryptography==1.2.3
cryptography1.8: cryptography==1.8.2
cryptography2.3: cryptography==2.3.1
py2.7: backports.test.support==0.1.1

commands =
sh -c '! tests/testapp/manage.py makemigrations --dry-run --exit --noinput'
Expand Down

0 comments on commit 6c733df

Please sign in to comment.