summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYury Selivanov <yury@magic.io>2018-04-03 00:10:20 -0400
committerYury Selivanov <yury@magic.io>2018-04-03 00:10:20 -0400
commit6140967d51cd7f0ce98bbce65f3f367b62eeb91a (patch)
tree7ec46c66fca39ef9055c3630b159dd91307add59
parent5804f0c47e60c7c2a0915cce2dbcfc7593881761 (diff)
downloadimmutables-6140967d51cd7f0ce98bbce65f3f367b62eeb91a.tar.gz
immutables-6140967d51cd7f0ce98bbce65f3f367b62eeb91a.zip
Make Map a subclass of collecitons.abc.Mapping
-rw-r--r--immutables/__init__.py3
-rw-r--r--immutables/_map.c2
-rw-r--r--immutables/map.py4
-rw-r--r--tests/test_map.py4
4 files changed, 12 insertions, 1 deletions
diff --git a/immutables/__init__.py b/immutables/__init__.py
index d598413..e900c2b 100644
--- a/immutables/__init__.py
+++ b/immutables/__init__.py
@@ -2,6 +2,9 @@ try:
from ._map import Map
except ImportError:
from .map import Map
+else:
+ import collections.abc as _abc
+ _abc.Mapping.register(Map)
__all__ = 'Map',
diff --git a/immutables/_map.c b/immutables/_map.c
index 3ed0393..be82cd9 100644
--- a/immutables/_map.c
+++ b/immutables/_map.c
@@ -3032,7 +3032,7 @@ static PyMappingMethods Map_as_mapping = {
PyTypeObject _Map_Type = {
PyVarObject_HEAD_INIT(NULL, 0)
- "Map",
+ "immutables._map.Map",
sizeof(MapObject),
.tp_methods = Map_methods,
.tp_as_mapping = &Map_as_mapping,
diff --git a/immutables/map.py b/immutables/map.py
index b6d55dc..83c02bc 100644
--- a/immutables/map.py
+++ b/immutables/map.py
@@ -1,3 +1,4 @@
+import collections.abc
import reprlib
@@ -457,3 +458,6 @@ class Map:
buf = []
self.__root.dump(buf, 0)
return '\n'.join(buf)
+
+
+collections.abc.Mapping.register(Map)
diff --git a/tests/test_map.py b/tests/test_map.py
index 3e7633a..7af9513 100644
--- a/tests/test_map.py
+++ b/tests/test_map.py
@@ -1,3 +1,4 @@
+import collections.abc
import gc
import random
import unittest
@@ -795,6 +796,9 @@ class BaseMapTest:
with HaskKeyCrasher(error_on_hash=True):
hash(m)
+ def test_abc_1(self):
+ self.assertTrue(issubclass(self.Map, collections.abc.Mapping))
+
class PyMapTest(BaseMapTest, unittest.TestCase):
cc-user)) (make-thing 42) EOF guix build -f "$module_dir/cc-user.scm" -n 2> "$module_dir/err" && false cat "$module_dir/err" grep "make-thing.*unbound" "$module_dir/err" # actual error grep "forget.*(bb-public)" "$module_dir/err" # hint rm -f "$module_dir"/* # Wrong 'define-module' clause reported by 'warn-about-load-error'. cat > "$module_dir/foo.scm" <<EOF (define-module (something foo) #:use-module (guix) #:use-module (gnu)) EOF guix build guile-bootstrap -n 2> "$module_dir/err" grep "does not match file name" "$module_dir/err" rm "$module_dir"/* # Should all return valid log files. drv="`guix build -d -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`" out="`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)'`" log="`guix build --log-file $drv`" echo "$log" | grep log/.*guile.*drv test -f "$log" test "`guix build -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' --log-file`" \ = "$log" test "`guix build --log-file guile-bootstrap`" = "$log" test "`guix build --log-file $out`" = "$log" # Should fail because the name/version combination could not be found. guix build hello-0.0.1 -n && false # Keep a symlink to the result, registered as a root. result="t-result-$$" guix build -r "$result" \ -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' test -x "$result/bin/guile" # Should fail, because $result already exists. guix build -r "$result" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' && false rm -f "$result" # Check relative file name canonicalization: <https://bugs.gnu.org/35271>. mkdir "$result" guix build -r "$result/x" -e '(@@ (gnu packages bootstrap) %bootstrap-guile)' test -x "$result/x/bin/guile" rm "$result/x" rmdir "$result" # Cross building. guix build coreutils --target=mips64el-linux-gnu --dry-run --no-substitutes # Likewise, but with '-e' (see <https://bugs.gnu.org/38093>). guix build --target=arm-linux-gnueabihf --dry-run \ -e '(@ (gnu packages base) coreutils)' # Replacements. drv1=`guix build guix --with-input=guile-zstd=idutils -d` drv2=`guix build guix -d` test "$drv1" != "$drv2" drv1=`guix build guile -d` drv2=`guix build guile --with-input=gimp=ruby -d` test "$drv1" = "$drv2" # See <https://bugs.gnu.org/42156>. drv1=`guix build glib -d` drv2=`guix build glib -d --with-input=libreoffice=inkscape` test "$drv1" = "$drv2" # '--with-graft' should have no effect when using '--no-grafts'. # See <https://bugs.gnu.org/43890>. drv1=`guix build inkscape -d --no-grafts` drv2=`guix build inkscape -d --no-grafts --with-graft=glib=glib-networking` test "$drv1" = "$drv2" # Rewriting implicit inputs. drv1=`guix build grep -d` drv2=`guix build grep -d --with-input=coreutils=hello` test "$drv1" != "$drv2" guix gc -R "$drv2" | grep `guix build -d hello` guix build guile --with-input=libunistring=something-really-silly && false # Deprecated/superseded packages. test "`guix build superseded -d`" = "`guix build bar -d`" # Parsing package names and versions. guix build -n time # PASS guix build -n time@1.9 # PASS, version found guix build -n time@3.2 && false # FAIL, version not found guix build -n something-that-will-never-exist && false # FAIL # Invoking a monadic procedure. guix build -e "(begin (use-modules (guix gexp)) (lambda () (gexp->derivation \"test\" (gexp (mkdir (ungexp output))))))" \ --dry-run # Running a gexp. guix build -e '#~(mkdir #$output)' -d guix build -e '#~(mkdir #$output)' -d | grep 'gexp\.drv' # Same with a file-like object. guix build -e '(computed-file "foo" #~(mkdir #$output))' -d guix build -e '(computed-file "foo" #~(mkdir #$output))' -d | grep 'foo\.drv' # Building from a package file. cat > "$module_dir/package.scm"<<EOF (use-modules (gnu)) (use-package-modules bootstrap) %bootstrap-guile EOF guix build --file="$module_dir/package.scm" # Building from a monadic procedure file. cat > "$module_dir/proc.scm"<<EOF (use-modules (guix gexp)) (lambda () (gexp->derivation "test" (gexp (mkdir (ungexp output))))) EOF guix build --file="$module_dir/proc.scm" --dry-run # Building from a gexp file. cat > "$module_dir/gexp.scm"<<EOF (use-modules (guix gexp)) (gexp (mkdir (ungexp output))) EOF guix build --file="$module_dir/gexp.scm" -d guix build --file="$module_dir/gexp.scm" -d | grep 'gexp\.drv' # Building from a manifest file. cat > "$module_dir/manifest.scm"<<EOF (specifications->manifest '("hello" "guix")) EOF test `guix build -d --manifest="$module_dir/manifest.scm" \ | grep -e '-hello-' -e '-guix-' \ | wc -l` -eq 2 # Building from a manifest that contains a non-package object. cat > "$module_dir/manifest.scm"<<EOF (manifest (list (manifest-entry (name "foo") (version "0") (item (computed-file "computed-thingie" #~(mkdir (ungexp output))))))) EOF guix build -d -m "$module_dir/manifest.scm" \ | grep 'computed-thingie\.drv$' rm "$module_dir"/*.scm if [ -n "$BASH_VERSION" ] then # Check whether we can load from a /dev/fd/N denoting a pipe, using this # handy Bash-specific construct. guix build -m <(echo '(specifications->manifest (list "guile"))') -n fi # Using 'GUIX_BUILD_OPTIONS'. GUIX_BUILD_OPTIONS="--dry-run --no-grafts" export GUIX_BUILD_OPTIONS guix build emacs GUIX_BUILD_OPTIONS="--something-completely-crazy" guix build emacs && false exit 0