From 97ecb0b5534c31c233b3ed17e74fb24148669520 Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Sat, 15 Jul 2017 16:54:43 -0700 Subject: [PATCH] Remove `apply` from tests --- tests/native_tests/contrib/multi.hy | 6 ++--- tests/native_tests/language.hy | 40 ++++++---------------------- tests/native_tests/native_macros.hy | 4 +-- tests/native_tests/operators.hy | 5 ---- tests/native_tests/py3_only_tests.hy | 9 +++---- tests/native_tests/tag_macros.hy | 5 ++-- 6 files changed, 19 insertions(+), 50 deletions(-) diff --git a/tests/native_tests/contrib/multi.hy b/tests/native_tests/contrib/multi.hy index 90c85dc..9b0294c 100644 --- a/tests/native_tests/contrib/multi.hy +++ b/tests/native_tests/contrib/multi.hy @@ -95,9 +95,9 @@ ([&optional [a "nop"] [b "p"]] (+ a b))) (assert (= (fun 1) 1)) - (assert (= (apply fun [] {"a" "t"}) "t")) - (assert (= (apply fun ["hello "] {"b" "world"}) "hello world")) - (assert (= (apply fun [] {"a" "hello " "b" "world"}) "hello world"))) + (assert (= (fun :a "t") "t")) + (assert (= (fun "hello " :b "world") "hello world")) + (assert (= (fun :a "hello " :b "world") "hello world"))) (defn test-docs [] diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index a284b39..51e221f 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -383,36 +383,12 @@ (defn test-kwargs [] "NATIVE: test kwargs things." - (assert (= (apply kwtest [] {"one" "two"}) {"one" "two"})) + (assert (= (kwtest :one "two") {"one" "two"})) (setv mydict {"one" "three"}) - (assert (= (apply kwtest [] mydict) mydict)) - (assert (= (apply kwtest [] ((fn [] {"one" "two"}))) {"one" "two"}))) + (assert (= (kwtest #** mydict) mydict)) + (assert (= (kwtest #** ((fn [] {"one" "two"}))) {"one" "two"}))) -(defn test-apply [] - "NATIVE: test working with args and functions" - (defn sumit [a b c] (+ a b c)) - (assert (= (apply sumit [1] {"b" 2 "c" 3}) 6)) - (assert (= (apply sumit [1 2 2]) 5)) - (assert (= (apply sumit [] {"a" 1 "b" 1 "c" 2}) 4)) - (assert (= (apply sumit ((fn [] [1 1])) {"c" 1}) 3)) - (defn noargs [] [1 2 3]) - (assert (= (apply noargs) [1 2 3])) - (defn sumit-mangle [an-a a-b a-c a-d] (+ an-a a-b a-c a-d)) - (def Z "a_d") - (assert (= (apply sumit-mangle [] {"an-a" 1 :a-b 2 'a-c 3 Z 4}) 10))) - - -(defn test-apply-with-methods [] - "NATIVE: test apply to call a method" - (setv str "foo {bar}") - (assert (= (apply .format [str] {"bar" "baz"}) - (apply .format ["foo {0}" "baz"]) - "foo baz")) - (setv lst ["a {0} {1} {foo} {bar}" "b" "c"]) - (assert (= (apply .format lst {"foo" "d" "bar" "e"}) - "a b c d e"))) - (defn test-dotted [] "NATIVE: test dotted invocation" @@ -430,20 +406,20 @@ (assert (= (.meth m) "meth")) (assert (= (.meth m "foo" "bar") "meth foo bar")) (assert (= (.meth :b "1" :a "2" m "foo" "bar") "meth foo bar 2 1")) - (assert (= (apply .meth [m "foo" "bar"]) "meth foo bar")) + (assert (= (.meth m #* ["foo" "bar"]) "meth foo bar")) (setv x.p m) (assert (= (.p.meth x) "meth")) (assert (= (.p.meth x "foo" "bar") "meth foo bar")) (assert (= (.p.meth :b "1" :a "2" x "foo" "bar") "meth foo bar 2 1")) - (assert (= (apply .p.meth [x "foo" "bar"]) "meth foo bar")) + (assert (= (.p.meth x #* ["foo" "bar"]) "meth foo bar")) (setv x.a (X)) (setv x.a.b m) (assert (= (.a.b.meth x) "meth")) (assert (= (.a.b.meth x "foo" "bar") "meth foo bar")) (assert (= (.a.b.meth :b "1" :a "2" x "foo" "bar") "meth foo bar 2 1")) - (assert (= (apply .a.b.meth [x "foo" "bar"]) "meth foo bar")) + (assert (= (.a.b.meth x #* ["foo" "bar"]) "meth foo bar")) (assert (is (.isdigit :foo) False))) @@ -1185,8 +1161,8 @@ "NATIVE: test &key function arguments" (defn foo [&key {"a" None "b" 1}] [a b]) (assert (= (foo) [None 1])) - (assert (= (apply foo [] {"a" 2}) [2 1])) - (assert (= (apply foo [] {"b" 42}) [None 42]))) + (assert (= (foo :a 2) [2 1])) + (assert (= (foo :b 42) [None 42]))) (defn test-optional-arguments [] diff --git a/tests/native_tests/native_macros.hy b/tests/native_tests/native_macros.hy index 3a0d428..d3efcb6 100644 --- a/tests/native_tests/native_macros.hy +++ b/tests/native_tests/native_macros.hy @@ -84,12 +84,12 @@ "NATIVE: test macro calling a plain function" (assert (= 3 (bar 1 2)))) -(defn test-optional-and-apply-in-macro [] +(defn test-optional-and-unpacking-in-macro [] ; https://github.com/hylang/hy/issues/1154 (defn f [&rest args] (+ "f:" (repr args))) (defmacro mac [&optional x] - `(apply f [~x])) + `(f #* [~x])) (assert (= (mac) "f:(None,)"))) (defn test-midtree-yield [] diff --git a/tests/native_tests/operators.hy b/tests/native_tests/operators.hy index b49c754..be40cc5 100644 --- a/tests/native_tests/operators.hy +++ b/tests/native_tests/operators.hy @@ -288,8 +288,3 @@ (assert (is (f 3 [1 2]) (!= f-name "in"))) (assert (is (f 2 [1 2]) (= f-name "in"))) (forbid (f 2 [1 2] [3 4]))) - -#@(pytest.mark.xfail -(defn test-apply-op [] - ; https://github.com/hylang/hy/issues/647 - (assert (= (eval '(apply + ["a" "b" "c"])) "abc")))) diff --git a/tests/native_tests/py3_only_tests.hy b/tests/native_tests/py3_only_tests.hy index b338ffa..84b8053 100644 --- a/tests/native_tests/py3_only_tests.hy +++ b/tests/native_tests/py3_only_tests.hy @@ -16,15 +16,15 @@ "NATIVE: test keyword-only arguments" ;; keyword-only with default works (defn kwonly-foo-default-false [&kwonly [foo False]] foo) - (assert (= (apply kwonly-foo-default-false) False)) - (assert (= (apply kwonly-foo-default-false [] {"foo" True}) True)) + (assert (= (kwonly-foo-default-false) False)) + (assert (= (kwonly-foo-default-false :foo True) True)) ;; keyword-only without default ... (defn kwonly-foo-no-default [&kwonly foo] foo) (setv attempt-to-omit-default (try (kwonly-foo-no-default) (except [e [Exception]] e))) ;; works - (assert (= (apply kwonly-foo-no-default [] {"foo" "quux"}) "quux")) + (assert (= (kwonly-foo-no-default :foo "quux") "quux")) ;; raises TypeError with appropriate message if not supplied (assert (isinstance attempt-to-omit-default TypeError)) (assert (in "missing 1 required keyword-only argument: 'foo'" @@ -32,8 +32,7 @@ ;; keyword-only with other arg types works (defn function-of-various-args [a b &rest args &kwonly foo &kwargs kwargs] (, a b args foo kwargs)) - (assert (= (apply function-of-various-args - [1 2 3 4] {"foo" 5 "bar" 6 "quux" 7}) + (assert (= (function-of-various-args 1 2 3 4 :foo 5 :bar 6 :quux 7) (, 1 2 (, 3 4) 5 {"bar" 6 "quux" 7})))) diff --git a/tests/native_tests/tag_macros.hy b/tests/native_tests/tag_macros.hy index ba586f6..18beaa7 100644 --- a/tests/native_tests/tag_macros.hy +++ b/tests/native_tests/tag_macros.hy @@ -100,9 +100,8 @@ "Increments each argument passed to the decorated function." ((wraps func) (fn [&rest args &kwargs kwargs] - (apply func - (map inc args) - (dict-comp k (inc v) [[k v] (.items kwargs)]))))) + (func #* (map inc args) + #** (dict-comp k (inc v) [[k v] (.items kwargs)]))))) #@(increment-arguments (defn foo [&rest args &kwargs kwargs]