Skip to content

Commit 2d695c9

Browse files
committed
Use the latest IRuby kernel in tests
1 parent d2d9815 commit 2d695c9

File tree

3 files changed

+52
-18
lines changed

3 files changed

+52
-18
lines changed

test/helper.rb

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
require "json"
33
require 'multi_json'
44
require "pathname"
5+
require "rbconfig"
56
require "test/unit"
67
require "test/unit/rr"
78
require "tmpdir"
@@ -11,9 +12,28 @@
1112

1213
module IRubyTest
1314
class TestBase < Test::Unit::TestCase
15+
TEST_DIR = File.expand_path("..", __FILE__).freeze
16+
BIN_DIR = File.expand_path("../bin", TEST_DIR).freeze
17+
LIB_DIR = File.expand_path("../lib", TEST_DIR).freeze
18+
19+
RUBY = RbConfig.ruby.freeze
20+
IRUBY_PATH = File.join(BIN_DIR, "iruby").freeze
21+
22+
def iruby_command(*args)
23+
[RUBY, "-I#{LIB_DIR}", IRUBY_PATH, *args]
24+
end
25+
1426
def self.startup
15-
@__config_dir = Dir.mktmpdir("iruby-test")
27+
@__work_dir = Dir.mktmpdir("iruby-test-data")
28+
29+
@__jupyter_data_dir = File.join(@__work_dir, "jupyter")
30+
ENV["JUPYTER_DATA_DIR"] = @__jupyter_data_dir
31+
system(RUBY, "-I#{LIB_DIR}", IRUBY_PATH, "register",
32+
err: :out, out: File::NULL)
33+
34+
@__config_dir = File.join(@__work_dir, "config")
1635
@__config_path = Pathname.new(@__config_dir) + "config.json"
36+
@__config_path.dirname.mkpath
1737
File.write(@__config_path, {
1838
control_port: 50160,
1939
shell_port: 57503,
@@ -30,7 +50,7 @@ def self.startup
3050
end
3151

3252
def self.shutdown
33-
FileUtils.remove_entry_secure(@__config_dir)
53+
FileUtils.remove_entry_secure(@__work_dir)
3454
end
3555

3656
def self.test_config_filename

test/iruby/command_test.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ def test_register_and_unregister_with_JUPYTER_DATA_DIR
150150
def test_register_and_unregister_with_JUPYTER_DATA_DIR_when_there_is_kernel_in_ipython_dir
151151
Dir.mktmpdir do |tmpdir|
152152
Dir.mktmpdir do |tmpdir2|
153-
with_env('HOME' => tmpdir2) do
153+
with_env("JUPYTER_DATA_DIR" => nil,
154+
"IPYTHONDIR" => nil,
155+
"HOME" => tmpdir2) do
154156
ignore_warning do
155157
@command = IRuby::Command.new(["register", "--ipython-dir=~/.ipython"])
156158
assert_equal("#{tmpdir2}/.ipython/kernels/ruby/kernel.json", @command.kernel_file)

test/iruby/jupyter_test.rb

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,37 @@
22

33
module IRubyTest
44
class JupyterDefaultKernelSpecDirectoryTest < TestBase
5-
def setup
6-
@kernelspec_dir = IRuby::Jupyter.kernelspec_dir
5+
sub_test_case("with JUPYTER_DATA_DIR") do
6+
def test_default
7+
assert_equal(File.join(ENV["JUPYTER_DATA_DIR"], "kernels"),
8+
IRuby::Jupyter.kernelspec_dir)
9+
end
710
end
811

9-
def test_default_windows
10-
windows_only
11-
appdata = IRuby::Jupyter.send :windows_user_appdata
12-
assert_equal(File.join(appdata, 'jupyter/kernels'), @kernelspec_dir)
13-
end
12+
sub_test_case("without JUPYTER_DATA_DIR environment variable") do
13+
def setup
14+
with_env("JUPYTER_DATA_DIR" => nil) do
15+
@kernelspec_dir = IRuby::Jupyter.kernelspec_dir
16+
yield
17+
end
18+
end
1419

15-
def test_default_apple
16-
apple_only
17-
assert_equal(File.expand_path('~/Library/Jupyter/kernels'), @kernelspec_dir)
18-
end
20+
def test_default_windows
21+
windows_only
22+
appdata = IRuby::Jupyter.send :windows_user_appdata
23+
assert_equal(File.join(appdata, 'jupyter/kernels'), @kernelspec_dir)
24+
end
25+
26+
def test_default_apple
27+
apple_only
28+
assert_equal(File.expand_path('~/Library/Jupyter/kernels'), @kernelspec_dir)
29+
end
1930

20-
def test_default_unix
21-
unix_only
22-
with_env('XDG_DATA_HOME' => nil) do
23-
assert_equal(File.expand_path('~/.local/share/jupyter/kernels'), @kernelspec_dir)
31+
def test_default_unix
32+
unix_only
33+
with_env('XDG_DATA_HOME' => nil) do
34+
assert_equal(File.expand_path('~/.local/share/jupyter/kernels'), @kernelspec_dir)
35+
end
2436
end
2537
end
2638
end

0 commit comments

Comments
 (0)