[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/pyim 0223242fac 1/4: Add pyim-tests-make-temp-file.
From: |
ELPA Syncer |
Subject: |
[elpa] externals/pyim 0223242fac 1/4: Add pyim-tests-make-temp-file. |
Date: |
Sat, 25 Dec 2021 19:57:39 -0500 (EST) |
branch: externals/pyim
commit 0223242fac2e090fa6579a2d83085413d39a7ae5
Author: Feng Shu <tumashu@163.com>
Commit: Feng Shu <tumashu@163.com>
Add pyim-tests-make-temp-file.
* tests/pyim-tests.el (pyim-tests-make-temp-file): New function.
(pyim-dcache-directory, pyim-tests-pyim-import-words-and-counts)
(pyim-tests-pyim-dcache-save/read-variable-value)
(pyim-tests-pyim-dcache-handle-variable)
(pyim-tests-pyim-dcache-export)
(pyim-tests-pyim-dhashcache-generate-file)
(pyim-tests-pyim-dhashcache-export): Use pyim-tests-make-temp-file.
---
tests/pyim-tests.el | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/tests/pyim-tests.el b/tests/pyim-tests.el
index 328752770a..6795847450 100644
--- a/tests/pyim-tests.el
+++ b/tests/pyim-tests.el
@@ -35,12 +35,14 @@
(require 'pyim-dregcache)
(require 'pyim-dhashcache)
+(defun pyim-tests-make-temp-file (&optional dir-flag)
+ (make-temp-file "pyim-tests-temp-" dir-flag))
+
(setq default-input-method "pyim")
(setq pyim-dicts nil)
(setq pyim-extra-dicts nil)
;; 设置 pyim-dcache-directory, 防止用户个人词库不小心被覆盖掉。
-(setq pyim-dcache-directory
- (file-name-as-directory (make-temp-name "pyim-tests-dcache-")))
+(setq pyim-dcache-directory (pyim-tests-make-temp-file t))
;; 做测试的时候不保存词库,防止因为误操作导致个人词库损坏。
(defalias 'pyim-kill-emacs-hook-function #'ignore)
@@ -567,9 +569,8 @@
(ert-deftest pyim-tests-pyim-import-words-and-counts ()
;; 这个测试目前主要用于手工测试,在 github 上这个测试无法通过的。
(when (not noninteractive)
- (let ((pyim-dcache-directory
- (file-name-as-directory (make-temp-name "pyim-tests-dcache-")))
- (file (make-temp-file "pyim-tests-import")))
+ (let ((pyim-dcache-directory (pyim-tests-make-temp-file t))
+ (file (pyim-tests-make-temp-file)))
;; 删除测试用词条
(dolist (x '("测㤅" "测嘊" "测伌"))
(pyim-process-delete-word x))
@@ -598,7 +599,7 @@
;; ** pyim-dcache 相关单元测试
(ert-deftest pyim-tests-pyim-dcache-save/read-variable-value ()
- (let* ((file (make-temp-file "pyim-tests-dcache-"))
+ (let* ((file (pyim-tests-make-temp-file))
(backup-file (concat file "-backup-" (format-time-string
"%Y%m%d%H%M%S")))
(value (make-hash-table :test #'equal)))
(puthash "ni-hao" (list "你好") value)
@@ -612,8 +613,7 @@
'("你好")))))
(ert-deftest pyim-tests-pyim-dcache-handle-variable ()
- (let ((pyim-dcache-directory
- (file-name-as-directory (make-temp-name "pyim-tests-dcache-")))
+ (let ((pyim-dcache-directory (pyim-tests-make-temp-file t))
my/test:1)
(pyim-dcache-save-variable 'my/test:1 "hello")
@@ -634,7 +634,7 @@
(ert-deftest pyim-tests-pyim-dcache-export ()
(let ((pyim-dhashcache-iword2count (make-hash-table :test #'equal))
(pyim-dhashcache-icode2word (make-hash-table :test #'equal))
- (file (make-temp-file "pyim-tests-dcache-export-")))
+ (file (pyim-tests-make-temp-file)))
(puthash "你好" 10 pyim-dhashcache-iword2count)
(puthash "尼耗" 1 pyim-dhashcache-iword2count)
(puthash "ni-hao" (list "你好" "尼耗") pyim-dhashcache-icode2word)
@@ -670,14 +670,15 @@ ni-hao 你好 尼耗
(should (equal (pyim-dhashcache-get-ishortcodes "") nil)))
(ert-deftest pyim-tests-pyim-dhashcache-get-path ()
- (let ((pyim-dcache-directory "/tmp/dcache"))
- (should (equal (pyim-dhashcache-get-path 'hello) "/tmp/dcache/hello"))
+ (let* ((dir (pyim-tests-make-temp-file t))
+ (pyim-dcache-directory dir))
+ (should (equal (pyim-dhashcache-get-path 'hello) (expand-file-name "hello"
dir)))
(should (equal (pyim-dhashcache-get-path "hello") nil))))
(ert-deftest pyim-tests-pyim-dhashcache-generate-file ()
- (let ((dist-file (make-temp-file "pyim-dist-"))
- (dcache-file (make-temp-file "pyim-tests-dcache-"))
- (word2code-dcache-file (make-temp-file "pyim-word2code-dcache-"))
+ (let ((dist-file (pyim-tests-make-temp-file))
+ (dcache-file (pyim-tests-make-temp-file))
+ (word2code-dcache-file (pyim-tests-make-temp-file))
output1 output2)
(with-temp-buffer
(insert ";; -*- coding: utf-8 -*--
@@ -775,7 +776,7 @@ zuo-zuo-you-mang 作作有芒")
(should (equal (gethash "你好" pyim-dhashcache-iword2count) 20))))
(ert-deftest pyim-tests-pyim-dhashcache-export ()
- (let ((file (make-temp-file "pyim-tests-dcache-"))
+ (let ((file (pyim-tests-make-temp-file))
(icode2word (make-hash-table :test #'equal)))
(puthash "yin-xing"
(list (propertize "银行" :noexport t)