iruby 0.7.4 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +80 -85
- data/CHANGES.md +21 -1
- data/README.md +19 -9
- data/Rakefile +2 -1
- data/exe/iruby +7 -0
- data/iruby.gemspec +3 -1
- data/lib/iruby/application.rb +380 -0
- data/lib/iruby/backend.rb +11 -2
- data/lib/iruby/error.rb +12 -0
- data/lib/iruby/jupyter.rb +4 -1
- data/lib/iruby/kernel.rb +4 -2
- data/lib/iruby/kernel_app.rb +108 -0
- data/lib/iruby/logger.rb +12 -2
- data/lib/iruby/session.rb +2 -0
- data/lib/iruby/version.rb +1 -1
- data/test/helper.rb +22 -3
- data/test/integration_test.rb +7 -1
- data/test/iruby/application/application_test.rb +32 -0
- data/test/iruby/application/console_test.rb +97 -0
- data/test/iruby/application/helper.rb +38 -0
- data/test/iruby/application/kernel_test.rb +93 -0
- data/test/iruby/application/register_test.rb +139 -0
- data/test/iruby/application/unregister_test.rb +77 -0
- data/test/iruby/jupyter_test.rb +27 -15
- data/test/iruby/kernel_test.rb +0 -2
- data/test/iruby/multi_logger_test.rb +13 -0
- data/test/run-test.rb +1 -0
- metadata +37 -11
- data/bin/iruby +0 -5
- data/lib/iruby/command.rb +0 -190
- data/test/iruby/command_test.rb +0 -207
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
module IRubyTest::ApplicationTests
|
4
|
+
class ApplicationTest < ApplicationTestBase
|
5
|
+
DEFAULT_KERNEL_NAME = IRuby::Application::DEFAULT_KERNEL_NAME
|
6
|
+
DEFAULT_DISPLAY_NAME = IRuby::Application::DEFAULT_DISPLAY_NAME
|
7
|
+
|
8
|
+
def test_help
|
9
|
+
out, status = Open3.capture2e(*iruby_command("--help"))
|
10
|
+
assert status.success?
|
11
|
+
assert_match(/--help/, out)
|
12
|
+
assert_match(/--version/, out)
|
13
|
+
assert_match(/^register\b/, out)
|
14
|
+
assert_match(/^unregister\b/, out)
|
15
|
+
assert_match(/^kernel\b/, out)
|
16
|
+
assert_match(/^console\b/, out)
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_version
|
20
|
+
out, status = Open3.capture2e(*iruby_command("--version"))
|
21
|
+
assert status.success?
|
22
|
+
assert_match(/\bIRuby\s+#{Regexp.escape(IRuby::VERSION)}\b/, out)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_unknown_subcommand
|
26
|
+
out, status = Open3.capture2e(*iruby_command("matz"))
|
27
|
+
refute status.success?
|
28
|
+
assert_match(/^Invalid subcommand name: matz$/, out)
|
29
|
+
assert_match(/^Subcommands$/, out)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
module IRubyTest::ApplicationTests
|
4
|
+
class ConsoleTest < ApplicationTestBase
|
5
|
+
def setup
|
6
|
+
Dir.mktmpdir do |tmpdir|
|
7
|
+
@fake_bin_dir = File.join(tmpdir, "bin")
|
8
|
+
FileUtils.mkdir_p(@fake_bin_dir)
|
9
|
+
|
10
|
+
@fake_data_dir = File.join(tmpdir, "data")
|
11
|
+
FileUtils.mkdir_p(@fake_data_dir)
|
12
|
+
|
13
|
+
new_path = [@fake_bin_dir, ENV["PATH"]].join(File::PATH_SEPARATOR)
|
14
|
+
with_env("PATH" => new_path,
|
15
|
+
"JUPYTER_DATA_DIR" => @fake_data_dir) do
|
16
|
+
yield
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
sub_test_case("there is the default IRuby kernel in JUPYTER_DATA_DIR") do
|
22
|
+
def setup
|
23
|
+
super do
|
24
|
+
ensure_iruby_kernel_is_installed
|
25
|
+
yield
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
test("run `jupyter console` with the default IRuby kernel") do
|
30
|
+
out, status = Open3.capture2e(*iruby_command("console"), in: :close)
|
31
|
+
assert status.success?
|
32
|
+
assert_match(/^Jupyter console [\d\.]+$/, out)
|
33
|
+
assert_match(/^#{Regexp.escape("IRuby #{IRuby::VERSION}")}\b/, out)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# NOTE: this case checks the priority of the default IRuby kernel when both kernels are available
|
38
|
+
sub_test_case("there are both the default IRuby kernel and IRuby kernel named `ruby` in JUPYTER_DATA_DIR") do
|
39
|
+
def setup
|
40
|
+
super do
|
41
|
+
ensure_iruby_kernel_is_installed
|
42
|
+
ensure_iruby_kernel_is_installed("ruby")
|
43
|
+
yield
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
test("run `jupyter console` with the default IRuby kernel") do
|
48
|
+
out, status = Open3.capture2e(*iruby_command("console"), in: :close)
|
49
|
+
assert status.success?
|
50
|
+
assert_match(/^Jupyter console [\d\.]+$/, out)
|
51
|
+
assert_match(/^#{Regexp.escape("IRuby #{IRuby::VERSION}")}\b/, out)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# NOTE: this case checks the availability of the old kernel name
|
56
|
+
sub_test_case("there is the IRuby kernel, which is named `ruby`, in JUPYTER_DATA_DIR") do
|
57
|
+
def setup
|
58
|
+
super do
|
59
|
+
ensure_iruby_kernel_is_installed("ruby")
|
60
|
+
yield
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
test("run `jupyter console` with the IRuby kernel `ruby`") do
|
65
|
+
out, status = Open3.capture2e(*iruby_command("console"), in: :close)
|
66
|
+
assert status.success?
|
67
|
+
assert_match(/^Jupyter console [\d\.]+$/, out)
|
68
|
+
assert_match(/^#{Regexp.escape("IRuby #{IRuby::VERSION}")}\b/, out)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
sub_test_case("with --kernel option") do
|
73
|
+
test("run `jupyter console` command with the given kernel name") do
|
74
|
+
kernel_name = "other-kernel-#{Process.pid}"
|
75
|
+
out, status = Open3.capture2e(*iruby_command("console", "--kernel=#{kernel_name}"))
|
76
|
+
refute status.success?
|
77
|
+
assert_match(/\bNo such kernel named #{Regexp.escape(kernel_name)}\b/, out)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
sub_test_case("no subcommand") do
|
82
|
+
def setup
|
83
|
+
super do
|
84
|
+
ensure_iruby_kernel_is_installed
|
85
|
+
yield
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
test("Run jupyter console command with the default IRuby kernel") do
|
90
|
+
out, status = Open3.capture2e(*iruby_command, in: :close)
|
91
|
+
assert status.success?
|
92
|
+
assert_match(/^Jupyter console [\d\.]+$/, out)
|
93
|
+
assert_match(/^#{Regexp.escape("IRuby #{IRuby::VERSION}")}\b/, out)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "helper"
|
2
|
+
require "open3"
|
3
|
+
require "rbconfig"
|
4
|
+
|
5
|
+
require "iruby/application"
|
6
|
+
|
7
|
+
module IRubyTest
|
8
|
+
module ApplicationTests
|
9
|
+
class ApplicationTestBase < TestBase
|
10
|
+
DEFAULT_KERNEL_NAME = IRuby::Application::DEFAULT_KERNEL_NAME
|
11
|
+
DEFAULT_DISPLAY_NAME = IRuby::Application::DEFAULT_DISPLAY_NAME
|
12
|
+
|
13
|
+
def ensure_iruby_kernel_is_installed(kernel_name=nil)
|
14
|
+
if kernel_name
|
15
|
+
system(*iruby_command("register", "--name=#{kernel_name}"), out: File::NULL, err: File::NULL)
|
16
|
+
else
|
17
|
+
system(*iruby_command("register"), out: File::NULL, err: File::NULL)
|
18
|
+
kernel_name = DEFAULT_KERNEL_NAME
|
19
|
+
end
|
20
|
+
kernel_json = File.join(ENV["JUPYTER_DATA_DIR"], "kernels", kernel_name, "kernel.json")
|
21
|
+
assert_path_exist kernel_json
|
22
|
+
|
23
|
+
# Insert -I option to add the lib directory in the $LOAD_PATH of the kernel process
|
24
|
+
modified_content = JSON.load(File.read(kernel_json))
|
25
|
+
kernel_index = modified_content["argv"].index("kernel")
|
26
|
+
modified_content["argv"].insert(kernel_index - 1, "-I#{LIB_DIR}")
|
27
|
+
File.write(kernel_json, JSON.pretty_generate(modified_content))
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_kernel_options(*additional_argv)
|
31
|
+
kernel_json = File.join(ENV["JUPYTER_DATA_DIR"], "kernels", DEFAULT_KERNEL_NAME, "kernel.json")
|
32
|
+
modified_content = JSON.load(File.read(kernel_json))
|
33
|
+
modified_content["argv"].concat(additional_argv)
|
34
|
+
File.write(kernel_json, JSON.pretty_generate(modified_content))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
module IRubyTest::ApplicationTests
|
4
|
+
class KernelTest < ApplicationTestBase
|
5
|
+
def setup
|
6
|
+
Dir.mktmpdir do |tmpdir|
|
7
|
+
@fake_bin_dir = File.join(tmpdir, "bin")
|
8
|
+
FileUtils.mkdir_p(@fake_bin_dir)
|
9
|
+
|
10
|
+
@fake_data_dir = File.join(tmpdir, "data")
|
11
|
+
FileUtils.mkdir_p(@fake_data_dir)
|
12
|
+
|
13
|
+
new_path = [@fake_bin_dir, ENV["PATH"]].join(File::PATH_SEPARATOR)
|
14
|
+
with_env("PATH" => new_path,
|
15
|
+
"JUPYTER_DATA_DIR" => @fake_data_dir) do
|
16
|
+
ensure_iruby_kernel_is_installed
|
17
|
+
yield
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
test("--test option dumps the given connection file") do
|
23
|
+
connection_info = {
|
24
|
+
"control_port" => 123456,
|
25
|
+
"shell_port" => 123457,
|
26
|
+
"transport" => "tcp",
|
27
|
+
"signature_scheme" => "hmac-sha256",
|
28
|
+
"stdin_port" => 123458,
|
29
|
+
"hb_port" => 123459,
|
30
|
+
"ip" => "127.0.0.1",
|
31
|
+
"iopub_port" => 123460,
|
32
|
+
"key" => "a0436f6c-1916-498b-8eb9-e81ab9368e84"
|
33
|
+
}
|
34
|
+
Dir.mktmpdir do |tmpdir|
|
35
|
+
connection_file = File.join(tmpdir, "connection.json")
|
36
|
+
File.write(connection_file, JSON.dump(connection_info))
|
37
|
+
out, status = Open3.capture2e(*iruby_command("kernel", "-f", connection_file, "--test"))
|
38
|
+
assert status.success?
|
39
|
+
assert_equal connection_info, JSON.load(out)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
test("the default log level is INFO") do
|
44
|
+
Dir.mktmpdir do |tmpdir|
|
45
|
+
boot_file = File.join(tmpdir, "boot.rb")
|
46
|
+
File.write(boot_file, <<~BOOT_SCRIPT)
|
47
|
+
puts "!!! INFO: \#{Logger::INFO}"
|
48
|
+
puts "!!! LOG LEVEL: \#{IRuby.logger.level}"
|
49
|
+
puts "!!! LOG LEVEL IS INFO: \#{IRuby.logger.level == Logger::INFO}"
|
50
|
+
BOOT_SCRIPT
|
51
|
+
|
52
|
+
add_kernel_options(boot_file)
|
53
|
+
|
54
|
+
out, status = Open3.capture2e(*iruby_command("console"), in: :close)
|
55
|
+
assert status.success?
|
56
|
+
assert_match(/^!!! LOG LEVEL IS INFO: true$/, out)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
test("--debug option makes the log level DEBUG") do
|
61
|
+
Dir.mktmpdir do |tmpdir|
|
62
|
+
boot_file = File.join(tmpdir, "boot.rb")
|
63
|
+
File.write(boot_file, <<~BOOT_SCRIPT)
|
64
|
+
puts "!!! LOG LEVEL IS DEBUG: \#{IRuby.logger.level == Logger::DEBUG}"
|
65
|
+
BOOT_SCRIPT
|
66
|
+
|
67
|
+
add_kernel_options("--debug", boot_file)
|
68
|
+
|
69
|
+
out, status = Open3.capture2e(*iruby_command("console"), in: :close)
|
70
|
+
assert status.success?
|
71
|
+
assert_match(/^!!! LOG LEVEL IS DEBUG: true$/, out)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
test("--log option adds a log destination file") do
|
76
|
+
Dir.mktmpdir do |tmpdir|
|
77
|
+
boot_file = File.join(tmpdir, "boot.rb")
|
78
|
+
File.write(boot_file, <<~BOOT_SCRIPT)
|
79
|
+
IRuby.logger.info("bootfile") { "!!! LOG MESSAGE FROM BOOT FILE !!!" }
|
80
|
+
BOOT_SCRIPT
|
81
|
+
|
82
|
+
log_file = File.join(tmpdir, "log.txt")
|
83
|
+
|
84
|
+
add_kernel_options("--log=#{log_file}", boot_file)
|
85
|
+
|
86
|
+
out, status = Open3.capture2e(*iruby_command("console"), in: :close)
|
87
|
+
assert status.success?
|
88
|
+
assert_path_exist log_file
|
89
|
+
assert_match(/\bINFO -- bootfile: !!! LOG MESSAGE FROM BOOT FILE !!!$/, File.read(log_file))
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
module IRubyTest::ApplicationTests
|
4
|
+
class RegisterTest < ApplicationTestBase
|
5
|
+
sub_test_case("when the existing IRuby kernel is in IPython's kernels directory") do
|
6
|
+
def setup
|
7
|
+
Dir.mktmpdir do |tmpdir|
|
8
|
+
ipython_dir = File.join(tmpdir, ".ipython")
|
9
|
+
# prepare the existing IRuby kernel with the default name
|
10
|
+
with_env("JUPYTER_DATA_DIR" => ipython_dir) do
|
11
|
+
ensure_iruby_kernel_is_installed
|
12
|
+
end
|
13
|
+
|
14
|
+
fake_bin_dir = File.join(tmpdir, "bin")
|
15
|
+
fake_jupyter = File.join(fake_bin_dir, "jupyter")
|
16
|
+
FileUtils.mkdir_p(fake_bin_dir)
|
17
|
+
IO.write(fake_jupyter, <<-FAKE_JUPYTER)
|
18
|
+
#!/usr/bin/env ruby
|
19
|
+
puts "Fake Jupyter"
|
20
|
+
FAKE_JUPYTER
|
21
|
+
File.chmod(0o755, fake_jupyter)
|
22
|
+
|
23
|
+
new_path = [fake_bin_dir, ENV["PATH"]].join(File::PATH_SEPARATOR)
|
24
|
+
with_env(
|
25
|
+
"HOME" => tmpdir,
|
26
|
+
"PATH" => new_path,
|
27
|
+
"JUPYTER_DATA_DIR" => nil,
|
28
|
+
"IPYTHONDIR" => nil
|
29
|
+
) do
|
30
|
+
yield
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
test("IRuby warns the existence of the kernel in IPython's kernels directory and executes `jupyter kernelspec install` command") do
|
36
|
+
out, status = Open3.capture2e(*iruby_command("register"))
|
37
|
+
assert status.success?
|
38
|
+
assert_match(/^Fake Jupyter$/, out)
|
39
|
+
assert_match(/^#{Regexp.escape("IRuby kernel `#{DEFAULT_KERNEL_NAME}` already exists in the deprecated IPython's data directory.")}$/,
|
40
|
+
out)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
sub_test_case("when the existing IRuby kernel is in Jupyter's default kernels directory") do
|
45
|
+
# TODO
|
46
|
+
end
|
47
|
+
|
48
|
+
sub_test_case("JUPYTER_DATA_DIR is supplied") do
|
49
|
+
def setup
|
50
|
+
Dir.mktmpdir do |tmpdir|
|
51
|
+
@kernel_json = File.join(tmpdir, "kernels", DEFAULT_KERNEL_NAME, "kernel.json")
|
52
|
+
with_env(
|
53
|
+
"JUPYTER_DATA_DIR" => tmpdir,
|
54
|
+
"IPYTHONDIR" => nil
|
55
|
+
) do
|
56
|
+
yield
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
test("a new IRuby kernel `#{DEFAULT_KERNEL_NAME}` will be installed in JUPYTER_DATA_DIR") do
|
62
|
+
assert_path_not_exist @kernel_json
|
63
|
+
|
64
|
+
out, status = Open3.capture2e(*iruby_command("register"))
|
65
|
+
assert status.success?
|
66
|
+
assert_path_exist @kernel_json
|
67
|
+
|
68
|
+
kernel = JSON.load(File.read(@kernel_json))
|
69
|
+
assert_equal DEFAULT_DISPLAY_NAME, kernel["display_name"]
|
70
|
+
end
|
71
|
+
|
72
|
+
sub_test_case("there is a IRuby kernel in JUPYTER_DATA_DIR") do
|
73
|
+
def setup
|
74
|
+
super do
|
75
|
+
FileUtils.mkdir_p(File.dirname(@kernel_json))
|
76
|
+
File.write(@kernel_json, '"dummy kernel"')
|
77
|
+
assert_equal '"dummy kernel"', File.read(@kernel_json)
|
78
|
+
yield
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
test("warn the existence of the kernel") do
|
83
|
+
out, status = Open3.capture2e(*iruby_command("register"))
|
84
|
+
refute status.success?
|
85
|
+
assert_match(/^#{Regexp.escape("IRuby kernel named `#{DEFAULT_KERNEL_NAME}` already exists!")}$/,
|
86
|
+
out)
|
87
|
+
assert_match(/^#{Regexp.escape("Use --force to force register the new kernel.")}$/,
|
88
|
+
out)
|
89
|
+
end
|
90
|
+
|
91
|
+
test("the existing kernel is not overwritten") do
|
92
|
+
_out, status = Open3.capture2e(*iruby_command("register"))
|
93
|
+
refute status.success?
|
94
|
+
assert_equal '"dummy kernel"', File.read(@kernel_json)
|
95
|
+
end
|
96
|
+
|
97
|
+
sub_test_case("`--force` option is specified") do
|
98
|
+
test("the existing kernel is overwritten by the new kernel") do
|
99
|
+
out, status = Open3.capture2e(*iruby_command("register", "--force"))
|
100
|
+
assert status.success?
|
101
|
+
assert_not_match(/^#{Regexp.escape("IRuby kernel named `#{DEFAULT_KERNEL_NAME}` already exists!")}$/,
|
102
|
+
out)
|
103
|
+
assert_not_match(/^#{Regexp.escape("Use --force to force register the new kernel.")}$/,
|
104
|
+
out)
|
105
|
+
assert_not_equal '"dummy kernel"', File.read(@kernel_json)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
sub_test_case("both JUPYTER_DATA_DIR and IPYTHONDIR are supplied") do
|
112
|
+
def setup
|
113
|
+
Dir.mktmpdir do |tmpdir|
|
114
|
+
Dir.mktmpdir do |tmpdir2|
|
115
|
+
with_env(
|
116
|
+
"JUPYTER_DATA_DIR" => tmpdir,
|
117
|
+
"IPYTHONDIR" => tmpdir2
|
118
|
+
) do
|
119
|
+
yield
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
test("warn for IPYTHONDIR") do
|
126
|
+
out, status = Open3.capture2e(*iruby_command("register"))
|
127
|
+
assert status.success?
|
128
|
+
assert_match(/^#{Regexp.escape("both JUPYTER_DATA_DIR and IPYTHONDIR are supplied; IPYTHONDIR is ignored.")}$/,
|
129
|
+
out)
|
130
|
+
end
|
131
|
+
|
132
|
+
test("a new kernel is installed in JUPYTER_DATA_DIR") do
|
133
|
+
_out, status = Open3.capture2e(*iruby_command("register"))
|
134
|
+
assert status.success?
|
135
|
+
assert_path_exist File.join(ENV["JUPYTER_DATA_DIR"], "kernels", DEFAULT_KERNEL_NAME, "kernel.json")
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
require_relative "helper"
|
2
|
+
|
3
|
+
module IRubyTest::ApplicationTests
|
4
|
+
class UnregisterTest < ApplicationTestBase
|
5
|
+
def setup
|
6
|
+
Dir.mktmpdir do |tmpdir|
|
7
|
+
@kernel_json = File.join(tmpdir, "kernels", DEFAULT_KERNEL_NAME, "kernel.json")
|
8
|
+
with_env(
|
9
|
+
"JUPYTER_DATA_DIR" => tmpdir,
|
10
|
+
"IPYTHONDIR" => nil
|
11
|
+
) do
|
12
|
+
yield
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
sub_test_case("when there is no IRuby kernel in JUPYTER_DATA_DIR") do
|
18
|
+
test("the command succeeds") do
|
19
|
+
assert system(*iruby_command("unregister", "-f", DEFAULT_KERNEL_NAME),
|
20
|
+
out: File::NULL, err: File::NULL)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
sub_test_case("when the existing IRuby kernel in JUPYTER_DATA_DIR") do
|
25
|
+
def setup
|
26
|
+
super do
|
27
|
+
ensure_iruby_kernel_is_installed
|
28
|
+
yield
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
test("uninstall the existing kernel") do
|
33
|
+
assert system(*iruby_command("unregister", "-f", DEFAULT_KERNEL_NAME),
|
34
|
+
out: File::NULL, err: File::NULL)
|
35
|
+
assert_path_not_exist @kernel_json
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
sub_test_case("when the existing IRuby kernel in IPython's kernels directory") do
|
40
|
+
def setup
|
41
|
+
super do
|
42
|
+
Dir.mktmpdir do |tmpdir|
|
43
|
+
ipython_dir = File.join(tmpdir, ".ipython")
|
44
|
+
|
45
|
+
# prepare the existing IRuby kernel with the default name
|
46
|
+
with_env("JUPYTER_DATA_DIR" => ipython_dir) do
|
47
|
+
ensure_iruby_kernel_is_installed
|
48
|
+
end
|
49
|
+
|
50
|
+
fake_bin_dir = File.join(tmpdir, "bin")
|
51
|
+
fake_jupyter = File.join(fake_bin_dir, "jupyter")
|
52
|
+
FileUtils.mkdir_p(fake_bin_dir)
|
53
|
+
IO.write(fake_jupyter, <<-FAKE_JUPYTER)
|
54
|
+
#!/usr/bin/env ruby
|
55
|
+
puts "Fake Jupyter"
|
56
|
+
FAKE_JUPYTER
|
57
|
+
File.chmod(0o755, fake_jupyter)
|
58
|
+
|
59
|
+
new_path = [fake_bin_dir, ENV["PATH"]].join(File::PATH_SEPARATOR)
|
60
|
+
with_env(
|
61
|
+
"HOME" => tmpdir,
|
62
|
+
"PATH" => new_path,
|
63
|
+
"IPYTHONDIR" => nil
|
64
|
+
) do
|
65
|
+
yield
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
test("the kernel in IPython's kernels directory is not removed") do
|
72
|
+
assert system(*iruby_command("unregister", "-f"), out: File::NULL, err: File::NULL)
|
73
|
+
assert_path_exist File.join(File.expand_path("~/.ipython"), "kernels", DEFAULT_KERNEL_NAME, "kernel.json")
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/test/iruby/jupyter_test.rb
CHANGED
@@ -2,25 +2,37 @@ require 'iruby/jupyter'
|
|
2
2
|
|
3
3
|
module IRubyTest
|
4
4
|
class JupyterDefaultKernelSpecDirectoryTest < TestBase
|
5
|
-
|
6
|
-
|
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
|
7
10
|
end
|
8
11
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
14
19
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
19
30
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
24
36
|
end
|
25
37
|
end
|
26
38
|
end
|
data/test/iruby/kernel_test.rb
CHANGED
@@ -8,4 +8,17 @@ class IRubyTest::MultiLoggerTest < IRubyTest::TestBase
|
|
8
8
|
assert_match 'bad thing', out.string
|
9
9
|
assert_match 'bad thing', err.string
|
10
10
|
end
|
11
|
+
|
12
|
+
def test_level
|
13
|
+
out, err = StringIO.new, StringIO.new
|
14
|
+
logger = IRuby::MultiLogger.new(Logger.new(out), Logger.new(err))
|
15
|
+
|
16
|
+
logger.level = Logger::DEBUG
|
17
|
+
assert_equal Logger::DEBUG, logger.level
|
18
|
+
assert_all(logger.loggers) {|l| l.level == Logger::DEBUG }
|
19
|
+
|
20
|
+
logger.level = Logger::INFO
|
21
|
+
assert_equal Logger::INFO, logger.level
|
22
|
+
assert_all(logger.loggers) {|l| l.level == Logger::INFO }
|
23
|
+
end
|
11
24
|
end
|
data/test/run-test.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Mendler
|
8
8
|
- The SciRuby developers
|
9
|
-
autorequire:
|
10
|
-
bindir:
|
9
|
+
autorequire:
|
10
|
+
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-07-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: data_uri
|
@@ -53,6 +53,20 @@ dependencies:
|
|
53
53
|
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: logger
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
type: :runtime
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
56
70
|
- !ruby/object:Gem::Dependency
|
57
71
|
name: mime-types
|
58
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -167,23 +181,24 @@ files:
|
|
167
181
|
- LICENSE
|
168
182
|
- README.md
|
169
183
|
- Rakefile
|
170
|
-
- bin/iruby
|
171
184
|
- ci/Dockerfile.base.erb
|
172
185
|
- ci/Dockerfile.main.erb
|
173
186
|
- ci/requirements.txt
|
174
187
|
- docker/setup.sh
|
175
188
|
- docker/test.sh
|
189
|
+
- exe/iruby
|
176
190
|
- ext/Rakefile
|
177
191
|
- iruby.gemspec
|
178
192
|
- lib/iruby.rb
|
193
|
+
- lib/iruby/application.rb
|
179
194
|
- lib/iruby/assets/kernel.css
|
180
195
|
- lib/iruby/assets/kernel.js
|
181
196
|
- lib/iruby/assets/logo-32x32.png
|
182
197
|
- lib/iruby/assets/logo-64x64.png
|
183
198
|
- lib/iruby/backend.rb
|
184
199
|
- lib/iruby/comm.rb
|
185
|
-
- lib/iruby/command.rb
|
186
200
|
- lib/iruby/display.rb
|
201
|
+
- lib/iruby/error.rb
|
187
202
|
- lib/iruby/event_manager.rb
|
188
203
|
- lib/iruby/formatter.rb
|
189
204
|
- lib/iruby/input.rb
|
@@ -207,6 +222,7 @@ files:
|
|
207
222
|
- lib/iruby/input/widget.rb
|
208
223
|
- lib/iruby/jupyter.rb
|
209
224
|
- lib/iruby/kernel.rb
|
225
|
+
- lib/iruby/kernel_app.rb
|
210
226
|
- lib/iruby/logger.rb
|
211
227
|
- lib/iruby/ostream.rb
|
212
228
|
- lib/iruby/session.rb
|
@@ -226,8 +242,13 @@ files:
|
|
226
242
|
- tasks/ci.rake
|
227
243
|
- test/helper.rb
|
228
244
|
- test/integration_test.rb
|
245
|
+
- test/iruby/application/application_test.rb
|
246
|
+
- test/iruby/application/console_test.rb
|
247
|
+
- test/iruby/application/helper.rb
|
248
|
+
- test/iruby/application/kernel_test.rb
|
249
|
+
- test/iruby/application/register_test.rb
|
250
|
+
- test/iruby/application/unregister_test.rb
|
229
251
|
- test/iruby/backend_test.rb
|
230
|
-
- test/iruby/command_test.rb
|
231
252
|
- test/iruby/display_test.rb
|
232
253
|
- test/iruby/event_manager_test.rb
|
233
254
|
- test/iruby/jupyter_test.rb
|
@@ -246,7 +267,7 @@ licenses:
|
|
246
267
|
- MIT
|
247
268
|
metadata:
|
248
269
|
msys2_mingw_dependencies: zeromq
|
249
|
-
post_install_message:
|
270
|
+
post_install_message:
|
250
271
|
rdoc_options: []
|
251
272
|
require_paths:
|
252
273
|
- lib
|
@@ -261,15 +282,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
261
282
|
- !ruby/object:Gem::Version
|
262
283
|
version: '0'
|
263
284
|
requirements: []
|
264
|
-
rubygems_version: 3.
|
265
|
-
signing_key:
|
285
|
+
rubygems_version: 3.5.11
|
286
|
+
signing_key:
|
266
287
|
specification_version: 4
|
267
288
|
summary: Ruby Kernel for Jupyter
|
268
289
|
test_files:
|
269
290
|
- test/helper.rb
|
270
291
|
- test/integration_test.rb
|
292
|
+
- test/iruby/application/application_test.rb
|
293
|
+
- test/iruby/application/console_test.rb
|
294
|
+
- test/iruby/application/helper.rb
|
295
|
+
- test/iruby/application/kernel_test.rb
|
296
|
+
- test/iruby/application/register_test.rb
|
297
|
+
- test/iruby/application/unregister_test.rb
|
271
298
|
- test/iruby/backend_test.rb
|
272
|
-
- test/iruby/command_test.rb
|
273
299
|
- test/iruby/display_test.rb
|
274
300
|
- test/iruby/event_manager_test.rb
|
275
301
|
- test/iruby/jupyter_test.rb
|