2020-09-18 23:08:09 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2020-11-23 20:31:16 +08:00
|
|
|
require 'tempfile'
|
2020-11-06 09:00:55 +08:00
|
|
|
require_relative '../test_helper'
|
2020-08-19 22:47:37 +08:00
|
|
|
|
2021-01-20 20:41:54 +08:00
|
|
|
class YouPlotIRISTest < Test::Unit::TestCase
|
2020-11-23 20:31:16 +08:00
|
|
|
class << self
|
|
|
|
def startup
|
|
|
|
@stdin = $stdin.dup
|
2020-12-16 11:50:06 +08:00
|
|
|
@stdout = $stdout.dup
|
2020-11-23 20:31:16 +08:00
|
|
|
@stderr = $stderr.dup
|
|
|
|
end
|
|
|
|
|
|
|
|
def shutdown
|
|
|
|
$stdin = @stdin
|
2020-12-16 11:50:06 +08:00
|
|
|
$stdout = @stdout
|
2020-11-23 20:31:16 +08:00
|
|
|
$stderr = @stderr
|
|
|
|
end
|
2020-11-23 19:09:32 +08:00
|
|
|
end
|
|
|
|
|
2020-11-23 16:14:43 +08:00
|
|
|
def setup
|
2020-11-23 20:31:16 +08:00
|
|
|
$stdin = File.open(File.expand_path('../fixtures/iris.csv', __dir__), 'r')
|
2020-12-16 11:50:06 +08:00
|
|
|
@stderr_file = Tempfile.new
|
|
|
|
@stdout_file = Tempfile.new
|
|
|
|
$stderr = @stderr_file
|
|
|
|
$stdout = @stdout_file
|
2020-11-23 16:14:43 +08:00
|
|
|
end
|
|
|
|
|
2020-11-23 20:31:16 +08:00
|
|
|
def teardown
|
2020-12-16 11:50:06 +08:00
|
|
|
@stderr_file.close
|
2020-11-23 19:09:32 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def fixture(fname)
|
|
|
|
File.read(File.expand_path("../fixtures/#{fname}", __dir__))
|
|
|
|
end
|
|
|
|
|
|
|
|
test :barplot do
|
2020-11-23 20:31:16 +08:00
|
|
|
YouPlot::Command.new(['barplot', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
2020-12-16 11:50:06 +08:00
|
|
|
assert_equal fixture('iris-barplot.txt'), @stderr_file.read
|
2020-11-23 20:31:16 +08:00
|
|
|
end
|
|
|
|
|
2021-05-29 08:45:29 +08:00
|
|
|
test :bar do
|
|
|
|
YouPlot::Command.new(['bar', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
|
|
|
assert_equal fixture('iris-barplot.txt'), @stderr_file.read
|
2020-11-23 20:31:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
test :histogram do
|
|
|
|
YouPlot::Command.new(['histogram', '-H', '-d,', '-t', 'IRIS-HISTOGRAM']).run
|
2020-12-16 11:50:06 +08:00
|
|
|
assert_equal fixture('iris-histogram.txt'), @stderr_file.read
|
2020-11-23 20:31:16 +08:00
|
|
|
end
|
|
|
|
|
2021-05-29 08:45:29 +08:00
|
|
|
test :hist do
|
|
|
|
YouPlot::Command.new(['hist', '-H', '-d,', '-t', 'IRIS-HISTOGRAM']).run
|
|
|
|
assert_equal fixture('iris-histogram.txt'), @stderr_file.read
|
2020-11-23 20:31:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
test :lineplot do
|
|
|
|
YouPlot::Command.new(['lineplot', '-H', '-d,', '-t', 'IRIS-LINEPLOT']).run
|
2020-12-16 11:50:06 +08:00
|
|
|
assert_equal fixture('iris-lineplot.txt'), @stderr_file.read
|
2020-11-23 20:31:16 +08:00
|
|
|
end
|
|
|
|
|
2021-05-29 08:45:29 +08:00
|
|
|
test :line do
|
|
|
|
YouPlot::Command.new(['line', '-H', '-d,', '-t', 'IRIS-LINEPLOT']).run
|
|
|
|
assert_equal fixture('iris-lineplot.txt'), @stderr_file.read
|
2020-11-23 20:31:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
test :lineplots do
|
|
|
|
YouPlot::Command.new(['lineplots', '-H', '-d,', '-t', 'IRIS-LINEPLOTS']).run
|
2020-12-16 11:50:06 +08:00
|
|
|
assert_equal fixture('iris-lineplots.txt'), @stderr_file.read
|
2020-11-23 20:31:16 +08:00
|
|
|
end
|
|
|
|
|
2021-05-29 08:45:29 +08:00
|
|
|
test :lines do
|
|
|
|
YouPlot::Command.new(['lines', '-H', '-d,', '-t', 'IRIS-LINEPLOTS']).run
|
|
|
|
assert_equal fixture('iris-lineplots.txt'), @stderr_file.read
|
2020-11-23 20:31:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
test :scatter do
|
|
|
|
YouPlot::Command.new(['scatter', '-H', '-d,', '-t', 'IRIS-SCATTER']).run
|
2020-12-16 11:50:06 +08:00
|
|
|
assert_equal fixture('iris-scatter.txt'), @stderr_file.read
|
2020-11-23 19:09:32 +08:00
|
|
|
end
|
|
|
|
|
2021-05-29 08:45:29 +08:00
|
|
|
test :s do
|
|
|
|
YouPlot::Command.new(['s', '-H', '-d,', '-t', 'IRIS-SCATTER']).run
|
|
|
|
assert_equal fixture('iris-scatter.txt'), @stderr_file.read
|
2020-11-23 20:31:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
test :density do
|
|
|
|
YouPlot::Command.new(['density', '-H', '-d,', '-t', 'IRIS-DENSITY']).run
|
2020-12-16 11:50:06 +08:00
|
|
|
assert_equal fixture('iris-density.txt'), @stderr_file.read
|
2020-11-23 20:31:16 +08:00
|
|
|
end
|
|
|
|
|
2021-05-29 08:45:29 +08:00
|
|
|
test :d do
|
|
|
|
YouPlot::Command.new(['d', '-H', '-d,', '-t', 'IRIS-DENSITY']).run
|
|
|
|
assert_equal fixture('iris-density.txt'), @stderr_file.read
|
2020-11-23 20:31:16 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
test :boxplot do
|
|
|
|
YouPlot::Command.new(['boxplot', '-H', '-d,', '-t', 'IRIS-BOXPLOT']).run
|
2020-12-16 11:50:06 +08:00
|
|
|
assert_equal fixture('iris-boxplot.txt'), @stderr_file.read
|
|
|
|
end
|
|
|
|
|
2021-05-29 08:45:29 +08:00
|
|
|
test :box do
|
|
|
|
YouPlot::Command.new(['box', '-H', '-d,', '-t', 'IRIS-BOXPLOT']).run
|
|
|
|
assert_equal fixture('iris-boxplot.txt'), @stderr_file.read
|
|
|
|
end
|
|
|
|
|
2021-01-20 21:21:37 +08:00
|
|
|
# test :c do
|
|
|
|
# YouPlot::Command.new(['count', '-H', '-d,']).run
|
|
|
|
# assert_equal fixture('iris-count.txt'), @stderr_file.read
|
|
|
|
# end
|
2021-01-19 21:36:36 +08:00
|
|
|
|
2021-01-20 21:21:37 +08:00
|
|
|
# test :count do
|
|
|
|
# YouPlot::Command.new(['c', '-H', '-d,']).run
|
|
|
|
# assert_equal fixture('iris-count.txt'), @stderr_file.read
|
|
|
|
# end
|
2021-01-19 21:36:36 +08:00
|
|
|
|
2020-12-16 11:50:06 +08:00
|
|
|
test :plot_output_stdout do
|
|
|
|
YouPlot::Command.new(['bar', '-o', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
2020-12-17 11:37:27 +08:00
|
|
|
assert_equal '', @stderr_file.read
|
2021-01-20 21:21:37 +08:00
|
|
|
assert_equal fixture('iris-barplot.txt'), @stdout_file.read
|
2020-12-16 11:50:06 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
test :data_output_stdout do
|
|
|
|
YouPlot::Command.new(['bar', '-O', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
|
|
|
assert_equal fixture('iris-barplot.txt'), @stderr_file.read
|
2021-01-20 21:21:37 +08:00
|
|
|
assert_equal fixture('iris.csv'), @stdout_file.read
|
2020-11-23 20:31:16 +08:00
|
|
|
end
|
2020-12-17 11:37:27 +08:00
|
|
|
|
|
|
|
%i[colors color colours colour].each do |cmd_name|
|
|
|
|
test cmd_name do
|
|
|
|
YouPlot::Command.new([cmd_name.to_s]).run
|
|
|
|
assert_equal fixture('colors.txt'), @stderr_file.read
|
|
|
|
assert_equal '', @stdout_file.read
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test :colors_output_stdout do
|
|
|
|
YouPlot::Command.new(['colors', '-o']).run
|
|
|
|
assert_equal '', @stderr_file.read
|
|
|
|
assert_equal fixture('colors.txt'), @stdout_file.read
|
|
|
|
end
|
2021-01-19 23:57:56 +08:00
|
|
|
|
|
|
|
test :unrecognized_command do
|
2021-05-27 20:49:53 +08:00
|
|
|
assert_raise(YouPlot::Parser::Error) do
|
2021-01-19 23:57:56 +08:00
|
|
|
YouPlot::Command.new(['abracadabra', '--hadley', '--wickham']).run
|
|
|
|
end
|
|
|
|
assert_equal '', @stderr_file.read
|
|
|
|
assert_equal '', @stdout_file.read
|
|
|
|
end
|
2021-01-20 22:54:54 +08:00
|
|
|
|
|
|
|
test :encoding do
|
|
|
|
$stdin = File.open(File.expand_path('../fixtures/iris_utf16.csv', __dir__), 'r')
|
|
|
|
YouPlot::Command.new(['s', '--encoding', 'UTF-16', '-H', '-d,', '-t', 'IRIS-SCATTER']).run
|
|
|
|
assert_equal fixture('iris-scatter.txt'), @stderr_file.read
|
|
|
|
end
|
2020-08-19 22:47:37 +08:00
|
|
|
end
|