iruby 0.7.4 → 0.8.1

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.
data/lib/iruby/session.rb CHANGED
@@ -2,6 +2,7 @@ require 'iruby/session_adapter'
2
2
  require 'iruby/session/mixin'
3
3
 
4
4
  require 'securerandom'
5
+ require 'time'
5
6
 
6
7
  module IRuby
7
8
  class Session
@@ -69,7 +70,7 @@ module IRuby
69
70
  end
70
71
  end
71
72
 
72
- def send(socket_type, message_type, content)
73
+ def send(socket_type, message_type, metadata = nil, content)
73
74
  sock = check_socket_type(socket_type)
74
75
  idents = if socket_type == :reply && @last_recvd_msg
75
76
  @last_recvd_msg[:idents]
@@ -79,11 +80,12 @@ module IRuby
79
80
  header = {
80
81
  msg_type: message_type,
81
82
  msg_id: SecureRandom.uuid,
83
+ date: Time.now.utc.iso8601,
82
84
  username: 'kernel',
83
85
  session: @session_id,
84
86
  version: '5.0'
85
87
  }
86
- @adapter.send(sock, serialize(idents, header, content))
88
+ @adapter.send(sock, serialize(idents, header, metadata, content))
87
89
  end
88
90
 
89
91
  def recv(socket_type)
data/lib/iruby/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module IRuby
2
- VERSION = '0.7.4'
2
+ VERSION = '0.8.1'
3
3
  end
data/test/helper.rb CHANGED
@@ -2,18 +2,36 @@ require "iruby"
2
2
  require "json"
3
3
  require 'multi_json'
4
4
  require "pathname"
5
+ require "rbconfig"
5
6
  require "test/unit"
6
7
  require "test/unit/rr"
7
8
  require "tmpdir"
8
9
 
9
-
10
10
  IRuby.logger = IRuby::MultiLogger.new(*Logger.new(STDERR, level: Logger::Severity::INFO))
11
11
 
12
12
  module IRubyTest
13
13
  class TestBase < Test::Unit::TestCase
14
+ TEST_DIR = File.expand_path("..", __FILE__).freeze
15
+ EXE_DIR = File.expand_path("../exe", TEST_DIR).freeze
16
+ LIB_DIR = File.expand_path("../lib", TEST_DIR).freeze
17
+
18
+ RUBY = RbConfig.ruby.freeze
19
+ IRUBY_PATH = File.join(EXE_DIR, "iruby").freeze
20
+
21
+ def iruby_command(*args)
22
+ [RUBY, "-I#{LIB_DIR}", IRUBY_PATH, *args]
23
+ end
24
+
14
25
  def self.startup
15
- @__config_dir = Dir.mktmpdir("iruby-test")
26
+ @__work_dir = Dir.mktmpdir("iruby-test-data")
27
+
28
+ @__jupyter_data_dir = File.join(@__work_dir, "jupyter")
29
+ @__save_jupyter_data_dir = ENV["JUPYTER_DATA_DIR"]
30
+ ENV["JUPYTER_DATA_DIR"] = @__jupyter_data_dir
31
+
32
+ @__config_dir = File.join(@__work_dir, "config")
16
33
  @__config_path = Pathname.new(@__config_dir) + "config.json"
34
+ @__config_path.dirname.mkpath
17
35
  File.write(@__config_path, {
18
36
  control_port: 50160,
19
37
  shell_port: 57503,
@@ -30,7 +48,8 @@ module IRubyTest
30
48
  end
31
49
 
32
50
  def self.shutdown
33
- FileUtils.remove_entry_secure(@__config_dir)
51
+ FileUtils.remove_entry_secure(@__work_dir)
52
+ ENV["JUPYTER_DATA_DIR"] = @__save_jupyter_data_dir
34
53
  end
35
54
 
36
55
  def self.test_config_filename
@@ -1,11 +1,17 @@
1
+ require 'bundler'
1
2
  require 'pty'
2
3
  require 'expect'
3
4
 
4
5
  class IRubyTest::IntegrationTest < IRubyTest::TestBase
5
6
  def setup
7
+ system(*iruby_command("register", "--name=iruby-test"), out: File::NULL, err: File::NULL)
8
+ kernel_json = File.join(ENV["JUPYTER_DATA_DIR"], "kernels", "iruby-test", "kernel.json")
9
+ assert_path_exist kernel_json
10
+
6
11
  $expect_verbose = false # make true if you want to dump the output of iruby console
7
12
 
8
- @in, @out, pid = PTY.spawn('bin/iruby --simple-prompt')
13
+ command = iruby_command("console", "--kernel=iruby-test").map {|x| %Q["#{x}"] }
14
+ @in, @out, pid = PTY.spawn(command.join(" "))
9
15
  @waiter = Thread.start { Process.waitpid(pid) }
10
16
  expect 'In [', 30
11
17
  expect '1'
@@ -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
@@ -2,25 +2,37 @@ require 'iruby/jupyter'
2
2
 
3
3
  module IRubyTest
4
4
  class JupyterDefaultKernelSpecDirectoryTest < TestBase
5
- def setup
6
- @kernel_spec = 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
7
10
  end
8
11
 
9
- def test_default_windows
10
- windows_only
11
- appdata = IRuby::Jupyter.send :windows_user_appdata
12
- assert_equal(File.join(appdata, 'jupyter/kernels'), @kernel_spec)
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
14
19
 
15
- def test_default_apple
16
- apple_only
17
- assert_equal(File.expand_path('~/Library/Jupyter/kernels'), @kernel_spec)
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
19
30
 
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'), @kernel_spec)
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
@@ -1,5 +1,3 @@
1
- require "base64"
2
-
3
1
  module IRubyTest
4
2
  class KernelTest < TestBase
5
3
  def setup
@@ -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
@@ -2,6 +2,7 @@
2
2
 
3
3
  $VERBOSE = true
4
4
 
5
+ require "bundler/setup"
5
6
  require "pathname"
6
7
 
7
8
  base_dir = Pathname.new(__dir__).parent.expand_path