-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make integer IntegerIdentifier pickleable so FK reverse accessor works
Merge remote-tracking branch 'origin/test-fk-reverse-relation' into develop
- Loading branch information
Showing
13 changed files
with
218 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,8 @@ db.sqlite3 | |
/dist | ||
*.egg-info | ||
.eggs | ||
.coverage | ||
.coverage | ||
/.project | ||
/.pydevproject | ||
/vagrant/.vagrant | ||
/.tox |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
from django import VERSION as DJANGO_VERSION | ||
|
||
DJANGO_VERSION_17 = DJANGO_VERSION < (1, 8) and (1, 7) <= DJANGO_VERSION | ||
DJANGO_VERSION_LT_18 = DJANGO_VERSION < (1, 8) | ||
DJANGO_VERSION_LT_18 = DJANGO_VERSION < (1, 8) | ||
DJANGO_VERSION_LT_19 = DJANGO_VERSION < (1, 9) | ||
DJANGO_VERSION_LT_20 = DJANGO_VERSION < (2, 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import copy | ||
import pickle | ||
|
||
from django.test import TestCase | ||
from randomfields.checks import DJANGO_VERSION_17 | ||
from randomfields.tests.models import TestIdentifierValue, TestIdentifierFKValue | ||
from randomfields.models.fields.integer import IntegerIdentifier | ||
from unittest import skipIf | ||
|
||
|
||
@skipIf(DJANGO_VERSION_17, "Not supported on Django 17") | ||
class IdentifierFKTests(TestCase): | ||
def test_reverse_accessor(self): | ||
obj = TestIdentifierValue.objects.create() | ||
rel = TestIdentifierFKValue.objects.create(data=obj) | ||
|
||
instance = TestIdentifierFKValue.objects.get(pk=rel.pk) | ||
|
||
# ensure we don't raise a type error when accessing the reverse relation | ||
# encountering the following exception when we do at the moment: | ||
# TypeError: __new__() missing 3 required positional arguments: 'possibilities', 'lower_bound', and 'upper_bound' | ||
# this issue began to occur in Django 2.0 and seems to be an issue | ||
# with copy/deepcopy and the IntegerIdentifier class | ||
instance.data | ||
|
||
def test_integer_identifier_copy(self): | ||
value = IntegerIdentifier(1, 3, -1, 1) | ||
value_copy = copy.copy(value) | ||
self.assertEqual(value, value_copy) | ||
|
||
def test_integer_identifier_deepcopy(self): | ||
value = IntegerIdentifier(1, 3, -1, 1) | ||
value_deepcopy = copy.deepcopy(value) | ||
self.assertEqual(value, value_deepcopy) | ||
|
||
def test_integer_identifier_pickle_dumps(self): | ||
value = IntegerIdentifier(1, 3, -1, 1) | ||
pickle.dumps(value) | ||
|
||
def test_integer_identifier_pickle_loads(self): | ||
value = IntegerIdentifier(1, 3, -1, 1) | ||
value_pickled = pickle.dumps(value) | ||
value_unpickled = pickle.loads(value_pickled) | ||
|
||
self.assertEqual(value, value_unpickled) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
host = RbConfig::CONFIG['host_os'] | ||
HOST_IS_MAC = host =~ /darwin/ | ||
HOST_IS_LINUX = host =~ /linux/ | ||
HOST_IS_WINDOWS = host =~ /mswin|mingw|cygwin/ | ||
|
||
if HOST_IS_MAC | ||
HOST_MEM = `sysctl -n hw.memsize`.to_i / 1024 / 1024 | ||
HOST_CPUS = `sysctl -n hw.ncpu`.to_i | ||
elsif HOST_IS_LINUX | ||
HOST_MEM = `grep 'MemTotal' /proc/meminfo | sed -e 's/MemTotal://' -e 's/ kB//'`.to_i / 1024 | ||
HOST_CPUS = `nproc`.to_i | ||
elsif HOST_IS_WINDOWS | ||
HOST_MEM = `wmic computersystem Get TotalPhysicalMemory`.split[1].to_i / 1024 / 1024 | ||
HOST_CPUS = `wmic cpu Get NumberOfCores`.split[1].to_i | ||
end | ||
|
||
Vagrant.configure("2") do |config| | ||
config.vm.boot_timeout = 600 | ||
config.vm.box = "bento/ubuntu-14.04" | ||
config.vm.box_url = "https://vagrantcloud.com/bento/boxes/ubuntu-14.04/versions/201802.02.0/providers/virtualbox.box" | ||
|
||
cpus = HOST_CPUS | ||
if 7000 < HOST_MEM | ||
mem = 4096 | ||
else | ||
mem = 2048 | ||
end | ||
|
||
config.vm.provider "virtualbox" do |v| | ||
v.name = "django-randomfields" | ||
v.memory = mem | ||
v.cpus = cpus | ||
if cpus > 1 | ||
v.customize ["modifyvm", :id, "--ioapic", "on"] | ||
end | ||
v.customize ["modifyvm", :id, "--cpuexecutioncap", "75"] | ||
end | ||
|
||
|
||
config.vm.provision :shell, path: "provision.sh" | ||
config.vm.synced_folder ".", "/vagrant", disabled: true | ||
config.vm.synced_folder "../", "/vagrant" | ||
|
||
|
||
# forward ports as listed in vagrant/vagrant/rebuild.sh | ||
# | ||
## | ||
## | ||
## THIS ALLOWS THE WEB BROWSER ON THE HOST MACHINE | ||
## TO COMMUNICATE VIA '127.0.0.1' or 'localhost' | ||
## i.e. `curl -i http://127.0.0.1:8080/` | ||
## | ||
## THIS ALSO ALLOWS NETWORKED MACHINES TO ACCESS FORWARDED | ||
## PORTS VIA THE HOST | ||
## i.e. `curl -i http://host-ip-or-fqdn:8080/ | ||
## | ||
## | ||
|
||
# responder http (use 8080 to avoid sudo requirement) | ||
config.vm.network "forwarded_port", guest: 80, host: 8080 | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
set -o errexit | ||
set -o pipefail | ||
set -o nounset | ||
shopt -s failglob | ||
set -o xtrace | ||
|
||
export DEBIAN_FRONTEND=noninteractive | ||
|
||
add-apt-repository ppa:deadsnakes/ppa | ||
|
||
apt-get update | ||
|
||
apt-get install -y git python3.5 python3.6 | ||
|
||
curl -O https://bootstrap.pypa.io/get-pip.py | ||
python get-pip.py | ||
|
||
pip install tox |