Skip to content

Commit

Permalink
Add test for generated image
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Oct 7, 2019
1 parent e20426f commit 9a16537
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 16 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dockerfiles/
34 changes: 24 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
---
dist: xenial
language: ruby
cache: bundler
rvm:
- 2.6
env:
- PYENV_VERSION=3.7 PYTHON=python
before_install:
- pip install --user matplotlib
notifications:
webhooks:
- https://webhook.commit-email.info/

services:
- docker

matrix:
include:
- name: Ruby 2.6
env: TYPE=ruby-2.6

install:
- docker build
-t red-data-tools/charty-${TYPE}
-f dockerfiles/Dockerfile.${TYPE}
.

script:
- docker run
--interactive
--tty
red-data-tools/charty-${TYPE}
bundle exec rake
13 changes: 7 additions & 6 deletions charty.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_development_dependency "activerecord"
spec.add_development_dependency "bundler", ">= 1.16"
spec.add_development_dependency "rake"
spec.add_development_dependency "test-unit"
spec.add_development_dependency "numo-narray"
spec.add_development_dependency "daru"
spec.add_development_dependency "matplotlib"
spec.add_development_dependency "nmatrix"
spec.add_development_dependency "numo-narray"
spec.add_development_dependency "rake"
spec.add_development_dependency "red-datasets", ">= 0.0.9"
spec.add_development_dependency "daru"
spec.add_development_dependency "activerecord"
spec.add_development_dependency "red-opencv"
spec.add_development_dependency "sqlite3"
spec.add_development_dependency "matplotlib"
spec.add_development_dependency "test-unit"
end
41 changes: 41 additions & 0 deletions dockerfiles/Dockerfile.ruby-2.6
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
FROM ruby:2.6

RUN \
apt update && \
apt install -y \
apt-transport-https \
wget && \
wget -O /usr/share/keyrings/red-data-tools-keyring.gpg \
https://packages.red-data-tools.org/debian/red-data-tools-keyring.gpg && \
echo "deb [signed-by=/usr/share/keyrings/red-data-tools-keyring.gpg] https://packages.red-data-tools.org/debian/ buster main" > \
/etc/apt/sources.list.d/red-data-tools.list && \
apt update && \
apt install -y \
python3-pip \
sudo \
xvfb && \
gem install \
bundler \
rake && \
pip3 install \
matplotlib

RUN \
useradd --user-group --create-home charty

RUN \
echo "charty ALL=(ALL:ALL) NOPASSWD:ALL" | \
EDITOR=tee visudo -f /etc/sudoers.d/charty

COPY . /home/charty/charty
RUN chown -R charty:charty /home/charty/charty

USER charty
WORKDIR /home/charty/charty

RUN bundle install

CMD \
dbus-run-session \
xvfb-run --server-args "-screen 0 640x480x24" \
bundle exec rake
Binary file added test/backends/pyplot/curve_integer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 28 additions & 0 deletions test/backends/pyplot/curve_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require_relative "../../test_helper"

class BackendsPyplotCurveTest < Test::Unit::TestCase
include Helper::Image

def setup
@plotter = Charty::Plotter.new(:pyplot)
@data = {
foo: [1, 2, 3, 4, 5, 6, 7],
square: [1, 4, 9, 16, 25, 36, 49],
cubic: [1, 8, 27, 64, 125, 216, 343],
}
end

def expected_image_path(*components)
File.join(__dir__, *components)
end

test("Integer") do
curve = @plotter.curve do
series [0, 1, 2, 3, 4], [10, 40, 20, 90, 70], label: "sample1"
end
output = Tempfile.new(["curve", ".png"])
curve.save(output.path)
assert_image(expected_image_path("curve_integer.png"),
output.path)
end
end
21 changes: 21 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'charty'
require 'test/unit'
require 'tempfile'
begin
require 'cv'
rescue LoadError
end


module Helper
module Image
def assert_image(expected_path, actual_path)
unless defined?(::CV)
omit("red-opencv is required for #{__method__}")
end
expected = CV::Image.read(expected_path)
actual = CV::Image.read(actual_path)
# TODO: Make this loose
assert_equal(expected.bytes.to_s,
actual.bytes.to_s)
end
end
end

0 comments on commit 9a16537

Please sign in to comment.