homebrew-core/Formula/buku.rb
Chongyu Zhu f87d7d538e
buku: fix test
Closes #35433.

Signed-off-by: Chongyu Zhu <i@lembacon.com>
2018-12-25 16:55:59 +08:00

156 lines
5.9 KiB
Ruby

class Buku < Formula
include Language::Python::Virtualenv
desc "Powerful command-line bookmark manager"
homepage "https://github.com/jarun/Buku"
url "https://github.com/jarun/Buku/archive/v4.0.tar.gz"
sha256 "35a3ebeeb715ec1170360570c3e43cb1308b67a75979ae264aac9961c778d2af"
bottle do
cellar :any
sha256 "100e3fc57f13252d6dcc696db05489ef101682c75cb36672a3cd9448989b7f1c" => :mojave
sha256 "0c4d313755bb83471bfc5e628a481ed75dc5b04d0895302f8d9e73a02d794565" => :high_sierra
sha256 "ff4114b5f5b115ddf1a316c7ef7103f35a558994b4166447c75c94802a7ab2d0" => :sierra
end
depends_on "openssl"
depends_on "python"
resource "asn1crypto" do
url "https://files.pythonhosted.org/packages/fc/f1/8db7daa71f414ddabfa056c4ef792e1461ff655c2ae2928a2b675bfed6b4/asn1crypto-0.24.0.tar.gz"
sha256 "9d5c20441baf0cb60a4ac34cc447c6c189024b6b4c6cd7877034f4965c464e49"
end
resource "beautifulsoup4" do
url "https://files.pythonhosted.org/packages/88/df/86bffad6309f74f3ff85ea69344a078fc30003270c8df6894fca7a3c72ff/beautifulsoup4-4.6.3.tar.gz"
sha256 "90f8e61121d6ae58362ce3bed8cd997efb00c914eae0ff3d363c32f9a9822d10"
end
resource "certifi" do
url "https://files.pythonhosted.org/packages/41/b6/4f0cefba47656583217acd6cd797bc2db1fede0d53090fdc28ad2c8e0716/certifi-2018.10.15.tar.gz"
sha256 "6d58c986d22b038c8c0df30d639f23a3e6d172a05c3583e766f4c0b785c0986a"
end
resource "cffi" do
url "https://files.pythonhosted.org/packages/e7/a7/4cd50e57cc6f436f1cc3a7e8fa700ff9b8b4d471620629074913e3735fb2/cffi-1.11.5.tar.gz"
sha256 "e90f17980e6ab0f3c2f3730e56d1fe9bcba1891eeea58966e89d352492cc74f4"
end
resource "cryptography" do
url "https://files.pythonhosted.org/packages/22/21/233e38f74188db94e8451ef6385754a98f3cad9b59bedf3a8e8b14988be4/cryptography-2.3.1.tar.gz"
sha256 "8d10113ca826a4c29d5b85b2c4e045ffa8bad74fb525ee0eceb1d38d4c70dfd6"
end
resource "html5lib" do
url "https://files.pythonhosted.org/packages/85/3e/cf449cf1b5004e87510b9368e7a5f1acd8831c2d6691edd3c62a0823f98f/html5lib-1.0.1.tar.gz"
sha256 "66cb0dcfdbbc4f9c3ba1a63fdb511ffdbd4f513b2b6d81b80cd26ce6b3fb3736"
end
resource "idna" do
url "https://files.pythonhosted.org/packages/65/c4/80f97e9c9628f3cac9b98bfca0402ede54e0563b56482e3e6e45c43c4935/idna-2.7.tar.gz"
sha256 "684a38a6f903c1d71d6d5fac066b58d7768af4de2b832e426ec79c30daa94a16"
end
resource "pycparser" do
url "https://files.pythonhosted.org/packages/68/9e/49196946aee219aead1290e00d1e7fdeab8567783e83e1b9ab5585e6206a/pycparser-2.19.tar.gz"
sha256 "a988718abfad80b6b157acce7bf130a30876d27603738ac39f140993246b25b3"
end
resource "six" do
url "https://files.pythonhosted.org/packages/16/d8/bc6316cf98419719bd59c91742194c111b6f2e85abac88e496adefaf7afe/six-1.11.0.tar.gz"
sha256 "70e8a77beed4562e7f14fe23a786b54f6296e34344c23bc42f07b15018ff98e9"
end
resource "urllib3" do
url "https://files.pythonhosted.org/packages/a5/74/05ffd00b4b5c08306939c485869f5dc40cbc27357195b0a98b18e4c48893/urllib3-1.24.tar.gz"
sha256 "41c3db2fc01e5b907288010dec72f9d0a74e37d6994e6eb56849f59fea2265ae"
end
resource "webencodings" do
url "https://files.pythonhosted.org/packages/0b/02/ae6ceac1baeda530866a85075641cec12989bd8d31af6d5ab4a3e8c92f47/webencodings-0.5.1.tar.gz"
sha256 "b36a1c245f2d304965eb4e0a82848379241dc04b865afcc4aab16748587e1923"
end
def install
venv = virtualenv_create(libexec, "python3")
venv.pip_install resources
# Replace shebang with virtualenv python
inreplace "buku.py", "#!/usr/bin/env python3", "#!#{libexec}/bin/python"
bin.install "buku.py" => "buku"
man1.install "buku.1"
bash_completion.install "auto-completion/bash/buku-completion.bash"
fish_completion.install "auto-completion/fish/buku.fish"
zsh_completion.install "auto-completion/zsh/_buku"
end
test do
ENV["LC_ALL"] = "en_US.UTF-8"
ENV["XDG_DATA_HOME"] = "#{testpath}/.local/share"
# Firefox exported bookmarks file
(testpath/"bookmarks.html").write <<~EOS
<!DOCTYPE NETSCAPE-Bookmark-file-1>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8">
<TITLE>Bookmarks</TITLE>
<H1>Bookmarks Menu</H1>
<DL><p>
<HR> <DT><H3 ADD_DATE="1464091987" LAST_MODIFIED="1477369518" PERSONAL_TOOLBAR_FOLDER="true">Bookmarks Toolbar</H3>
<DD>Add bookmarks to this folder to see them displayed on the Bookmarks Toolbar
<DL><p>
<DT><A HREF="https://github.com/Homebrew/brew" ADD_DATE="1477369518" LAST_MODIFIED="1477369529">Title unknown</A>
</DL><p>
</DL>
EOS
(testpath/"import").write <<~EOS
spawn #{bin}/buku --nc --import bookmarks.html
expect -re "DB file is being created at .*"
expect "You should encrypt it."
expect "Append tags when bookmark exist? (y/n): "
send "y\r"
expect "Add parent folder names as tags? (y/n): "
send "y\r"
expect {
-re ".*ERROR.*" { exit 1 }
"1. Title unknown"
}
spawn sleep 5
EOS
system "/usr/bin/expect", "-f", "import"
# Test online components -- fetch titles
system bin/"buku", "--update"
# Test crypto functionality
(testpath/"crypto-test").write <<~EOS
# Lock bookmark database
spawn #{bin}/buku --lock
expect "Password: "
send "password\r"
expect "Password: "
send "password\r"
expect {
-re ".*ERROR.*" { exit 1 }
"File encrypted"
}
# Unlock bookmark database
spawn #{bin}/buku --unlock
expect "Password: "
send "password\r"
expect {
-re ".*ERROR.*" { exit 1 }
"File decrypted"
}
EOS
system "/usr/bin/expect", "-f", "crypto-test"
# Test database content and search
result = shell_output("#{bin}/buku --np --sany Homebrew")
assert_match "https://github.com/Homebrew/brew", result
assert_match "The Homebrew package manager", result
end
end