2021-01-20 20:41:54 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'tempfile'
|
|
|
|
require_relative '../test_helper'
|
|
|
|
|
|
|
|
class YouPlotSimpleTest < Test::Unit::TestCase
|
|
|
|
class << self
|
|
|
|
def startup
|
|
|
|
@stdin = $stdin.dup
|
|
|
|
@stdout = $stdout.dup
|
|
|
|
@stderr = $stderr.dup
|
|
|
|
end
|
|
|
|
|
|
|
|
def shutdown
|
|
|
|
$stdin = @stdin
|
|
|
|
$stdout = @stdout
|
|
|
|
$stderr = @stderr
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup
|
|
|
|
$stdin = File.open(File.expand_path('../fixtures/simple.tsv', __dir__), 'r')
|
|
|
|
@stderr_file = Tempfile.new
|
|
|
|
@stdout_file = Tempfile.new
|
|
|
|
$stderr = @stderr_file
|
|
|
|
$stdout = @stdout_file
|
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
@stderr_file.close
|
|
|
|
end
|
|
|
|
|
|
|
|
def fixture(fname)
|
|
|
|
File.read(File.expand_path("../fixtures/#{fname}", __dir__))
|
|
|
|
end
|
|
|
|
|
|
|
|
test :bar do
|
|
|
|
assert_raise(ArgumentError) do
|
|
|
|
YouPlot::Command.new(['bar']).run
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-01-20 21:21:37 +08:00
|
|
|
test :barplot do
|
|
|
|
assert_raise(ArgumentError) do
|
|
|
|
YouPlot::Command.new(['barplot']).run
|
|
|
|
end
|
|
|
|
end
|
2021-01-20 20:41:54 +08:00
|
|
|
|
2021-01-20 21:21:37 +08:00
|
|
|
test :hist do
|
|
|
|
YouPlot::Command.new(['hist']).run
|
|
|
|
assert_equal fixture('simple-histogram.txt'), @stderr_file.read
|
|
|
|
end
|
2021-01-20 20:41:54 +08:00
|
|
|
|
2021-01-20 21:21:37 +08:00
|
|
|
test :histogram do
|
|
|
|
YouPlot::Command.new(['histogram']).run
|
|
|
|
assert_equal fixture('simple-histogram.txt'), @stderr_file.read
|
|
|
|
end
|
2021-01-20 20:41:54 +08:00
|
|
|
|
2021-01-20 21:21:37 +08:00
|
|
|
test :line do
|
|
|
|
YouPlot::Command.new(['line']).run
|
|
|
|
assert_equal fixture('simple-lineplot.txt'), @stderr_file.read
|
|
|
|
end
|
2021-01-20 20:41:54 +08:00
|
|
|
|
2021-01-20 21:21:37 +08:00
|
|
|
test :lineplot do
|
|
|
|
YouPlot::Command.new(['lineplot']).run
|
|
|
|
assert_equal fixture('simple-lineplot.txt'), @stderr_file.read
|
|
|
|
end
|
2021-01-20 20:41:54 +08:00
|
|
|
|
2021-01-20 21:21:37 +08:00
|
|
|
test :lines do
|
|
|
|
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do
|
|
|
|
YouPlot::Command.new(['lines']).run
|
|
|
|
end
|
|
|
|
end
|
2021-01-20 20:41:54 +08:00
|
|
|
|
2021-01-20 21:21:37 +08:00
|
|
|
test :lineplots do
|
|
|
|
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do
|
|
|
|
YouPlot::Command.new(['lineplots']).run
|
|
|
|
end
|
|
|
|
end
|
2021-01-20 20:41:54 +08:00
|
|
|
|
2021-01-20 21:21:37 +08:00
|
|
|
test :s do
|
|
|
|
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do
|
|
|
|
YouPlot::Command.new(['s']).run
|
|
|
|
end
|
|
|
|
end
|
2021-01-20 20:41:54 +08:00
|
|
|
|
2021-01-20 21:21:37 +08:00
|
|
|
test :scatter do
|
|
|
|
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do
|
|
|
|
YouPlot::Command.new(['scatter']).run
|
|
|
|
end
|
|
|
|
end
|
2021-01-20 20:41:54 +08:00
|
|
|
|
2021-01-20 21:21:37 +08:00
|
|
|
test :d do
|
|
|
|
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do
|
|
|
|
YouPlot::Command.new(['d']).run
|
|
|
|
end
|
|
|
|
end
|
2021-01-20 20:41:54 +08:00
|
|
|
|
2021-01-20 21:21:37 +08:00
|
|
|
test :density do
|
|
|
|
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do
|
|
|
|
YouPlot::Command.new(['density']).run
|
|
|
|
end
|
|
|
|
end
|
2021-01-20 20:41:54 +08:00
|
|
|
|
2021-01-20 21:21:37 +08:00
|
|
|
test :box do
|
|
|
|
YouPlot::Command.new(['box']).run
|
|
|
|
assert_equal fixture('simple-boxplot.txt'), @stderr_file.read
|
|
|
|
end
|
2021-01-20 20:41:54 +08:00
|
|
|
|
2021-01-20 21:21:37 +08:00
|
|
|
test :boxplot do
|
|
|
|
YouPlot::Command.new(['boxplot']).run
|
|
|
|
assert_equal fixture('simple-boxplot.txt'), @stderr_file.read
|
|
|
|
end
|
2021-01-20 20:41:54 +08:00
|
|
|
|
|
|
|
# test :c do
|
|
|
|
# omit
|
|
|
|
# YouPlot::Command.new(['count', '-H', '-d,']).run
|
|
|
|
# assert_equal fixture('iris-count.txt'), @stderr_file.read
|
|
|
|
# end
|
|
|
|
|
|
|
|
# test :count do
|
|
|
|
# omit
|
|
|
|
# YouPlot::Command.new(['c', '-H', '-d,']).run
|
|
|
|
# assert_equal fixture('iris-count.txt'), @stderr_file.read
|
|
|
|
# end
|
|
|
|
|
2021-01-20 21:21:37 +08:00
|
|
|
test :plot_output_stdout do
|
|
|
|
YouPlot::Command.new(['line', '-o']).run
|
|
|
|
assert_equal '', @stderr_file.read
|
|
|
|
assert_equal fixture('simple-lineplot.txt'), @stdout_file.read
|
|
|
|
end
|
2021-01-20 20:41:54 +08:00
|
|
|
|
2021-01-20 21:21:37 +08:00
|
|
|
test :data_output_stdout do
|
|
|
|
YouPlot::Command.new(['box', '-O']).run
|
|
|
|
assert_equal fixture('simple-boxplot.txt'), @stderr_file.read
|
|
|
|
assert_equal fixture('simple.tsv'), @stdout_file.read
|
|
|
|
end
|
2021-01-20 22:10:10 +08:00
|
|
|
|
|
|
|
test :line_transpose do
|
|
|
|
$stdin = File.open(File.expand_path('../fixtures/simpleT.tsv', __dir__), 'r')
|
|
|
|
YouPlot::Command.new(['line', '--transpose']).run
|
|
|
|
assert_equal fixture('simple-lineplot.txt'), @stderr_file.read
|
|
|
|
end
|
|
|
|
|
|
|
|
test :line_T do
|
|
|
|
$stdin = File.open(File.expand_path('../fixtures/simpleT.tsv', __dir__), 'r')
|
|
|
|
YouPlot::Command.new(['line', '-T']).run
|
|
|
|
assert_equal fixture('simple-lineplot.txt'), @stderr_file.read
|
|
|
|
end
|
|
|
|
|
|
|
|
test :line_xlabel do
|
|
|
|
YouPlot::Command.new(['line', '--xlabel', 'X-LABEL']).run
|
|
|
|
assert_equal fixture('simple-lineplot-xlabel.txt'), @stderr_file.read
|
|
|
|
end
|
|
|
|
|
|
|
|
test :line_ylabel do
|
|
|
|
YouPlot::Command.new(['line', '--ylabel', 'Y-LABEL']).run
|
|
|
|
assert_equal fixture('simple-lineplot-ylabel.txt'), @stderr_file.read
|
|
|
|
end
|
2021-01-20 20:41:54 +08:00
|
|
|
end
|