mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-06-24 18:11:12 +08:00
Start testing the command line interface
This commit is contained in:
parent
7a08d6bab9
commit
0ff8c6a9f0
@ -13,14 +13,15 @@ module YouPlot
|
||||
attr_accessor :params
|
||||
attr_reader :data, :fmt, :parser
|
||||
|
||||
def initialize
|
||||
def initialize(argv = ARGV)
|
||||
@argv = argv
|
||||
@params = Params.new
|
||||
@parser = Parser.new
|
||||
@backend = YouPlot::Backends::UnicodePlotBackend
|
||||
end
|
||||
|
||||
def run
|
||||
parser.parse_options
|
||||
parser.parse_options(@argv)
|
||||
command = parser.command
|
||||
params = parser.params
|
||||
delimiter = parser.delimiter
|
||||
@ -62,7 +63,8 @@ module YouPlot
|
||||
raise "unrecognized plot_type: #{command}"
|
||||
end
|
||||
|
||||
if output.is_a?(IO)
|
||||
case output
|
||||
when IO
|
||||
plot.render(output)
|
||||
else
|
||||
File.open(output, 'w') do |f|
|
||||
@ -70,9 +72,11 @@ module YouPlot
|
||||
end
|
||||
end
|
||||
|
||||
if pass.is_a?(IO)
|
||||
print input
|
||||
elsif pass
|
||||
case pass
|
||||
when IO
|
||||
pass.print(input)
|
||||
else
|
||||
if pass
|
||||
File.open(pass, 'w') do |f|
|
||||
f.print(input)
|
||||
end
|
||||
@ -81,3 +85,4 @@ module YouPlot
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
20
test/fixtures/iris-scatter.txt
vendored
Normal file
20
test/fixtures/iris-scatter.txt
vendored
Normal file
@ -0,0 +1,20 @@
|
||||
IRIS
|
||||
┌────────────────────────────────────────┐
|
||||
6.9 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠄⠃⠀⠀│ sepal_width
|
||||
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⡄⠂⠄⠀⠀⠄⠀⠁│ petal_length
|
||||
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⡀⡀⠂⠀⡆⠁⠄⠈⠀⠂⠀⠀⠀⠀⠀⠀⠀│ petal_width
|
||||
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⡀⡀⠀⠂⡀⠃⡅⠀⠄⠁⡂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ species
|
||||
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠐⠀⠁⠀⠄⢕⠀⠄⡃⠀⠀⠀⡁⠄⠂⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
|
||||
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠁⠀⠀⠀⠀⠁⣊⠀⡃⠀⡀⠉⠀⠅⠂⠅⠙⠀⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
|
||||
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⠀⢅⠀⡄⡮⠀⠅⠇⠀⠒⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠄⠀⠄│
|
||||
│⠀⠀⠀⠀⠀⠨⠀⠠⠀⡀⣷⠀⠆⠀⠄⠊⠀⠂⠀⠀⠄⠀⠄⡄⠀⠀⠀⡀⠀⠀⠀⠀⠁⠀⠀⠀⠀⠀⠀⠀│
|
||||
│⠀⠀⠐⠀⠇⠘⠀⠑⠀⠂⠓⠀⠀⠀⠂⢰⠀⡆⡀⠃⢶⠀⡄⡄⡇⡳⠀⠂⡃⠃⠑⠀⠃⠄⡀⠀⠂⡂⠀⠀│
|
||||
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⡄⠠⠀⠁⠀⠀⡮⠀⠆⡃⠀⠑⠀⠀⡅⠁⠀⠀⡄⠀⠀⠀⠀⠄⠀⠀⠀⠀⠂⠀⠀│
|
||||
│⠀⠀⠀⠀⠀⠁⠀⢀⠀⠀⢅⠀⠀⠀⠀⠡⠀⠄⡀⠀⠁⠀⠁⡁⡃⠅⠀⠃⠃⠃⠐⠀⠀⠀⡀⠀⠂⠅⠀⠄│
|
||||
│⠀⠀⠀⠀⡀⢠⠀⢤⠀⡆⣴⠀⡤⠀⠆⡠⠀⠆⠀⠅⢍⠀⠅⠅⠅⢅⠀⡇⡀⠄⡀⠀⠅⠁⠀⠀⠀⠀⠀⠀│
|
||||
│⠀⠀⠠⠀⠁⢁⠀⠁⠀⡀⡣⠀⠀⠀⠁⡯⠀⡃⡂⠀⡘⠀⠁⠁⠁⠈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
|
||||
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
|
||||
0 │⠀⠀⢀⠀⡄⣲⠀⣴⠀⡄⣿⠀⣤⠀⡅⣄⠀⡃⡄⡀⣀⠀⡀⡀⡀⣀⠀⡀⡀⡀⣀⠀⡀⡀⡀⠀⡀⡀⠀⡀│
|
||||
└────────────────────────────────────────┘
|
||||
4 8
|
||||
sepal_length
|
@ -1,6 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "tempfile"
|
||||
require_relative '../test_helper'
|
||||
|
||||
class YouPlotCommandTest < Test::Unit::TestCase
|
||||
def setup
|
||||
@ta = "ta"
|
||||
@stdin = $stdin.dup
|
||||
@stderr = $stderr.dup
|
||||
end
|
||||
|
||||
test :scatter do
|
||||
$stdin = File.open(File.expand_path("../fixtures/iris.csv", __dir__), "r")
|
||||
Tempfile.new("iris-scatter") do |tmp_file|
|
||||
$stderr = tmp_file
|
||||
YouPlot::Command.new(["scatter", "-H", "-d,", "-t", "IRIS"]).run
|
||||
assert_equal File.read(File.expand_path("../fixtures/iris-scatter.txt", __dir__)), tmp_file.read
|
||||
end
|
||||
$stdin = @stdin
|
||||
$stderr = @stderr
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user