ruby-graphviz 1.0.9 → 1.1.0

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.
@@ -34,19 +34,6 @@ class GraphViz
34
34
  return nil
35
35
  end
36
36
 
37
- def escape_path_containing_blanks(path) #:nodoc:
38
- path.gsub!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
39
- path_elements = path.split(File::SEPARATOR)
40
- path_elements.map! do |element|
41
- if element.include?(' ')
42
- "\"#{element}\""
43
- else
44
- element
45
- end
46
- end
47
- path_elements.join(File::SEPARATOR)
48
- end
49
-
50
37
  def output_and_errors_from_command(cmd) #:nodoc:
51
38
  unless defined? Open3
52
39
  begin
@@ -56,22 +43,19 @@ class GraphViz
56
43
  end
57
44
  end
58
45
  begin
59
- Open3.popen3( cmd ) do |stdin, stdout, stderr|
60
- stdin.close
61
- stdout.binmode
62
- [stdout.read, stderr.read]
63
- end
46
+ out, err, status = Open3.capture3(*cmd)
47
+ [out, err, status.exitstatus]
64
48
  rescue NotImplementedError, NoMethodError
65
- IO.popen( cmd ) do |stdout|
49
+ IO.popen( *cmd ) do |stdout|
66
50
  stdout.binmode
67
- [stdout.read, nil]
51
+ [stdout.read, nil, nil]
68
52
  end
69
53
  end
70
54
  end
71
55
 
72
56
  def output_from_command(cmd) #:nodoc:
73
- output, errors = output_and_errors_from_command(cmd)
74
- if errors.nil? || errors.strip.empty?
57
+ output, errors, status = output_and_errors_from_command(cmd)
58
+ if (status.nil? && (errors.nil? || errors.strip.empty?)) || status.zero?
75
59
  output
76
60
  else
77
61
  raise "Error from #{cmd}:\n#{errors}"
@@ -35,17 +35,13 @@ For more information about Ruby-Graphviz :
35
35
  * NEW - Mailing List : http://groups.google.com/group/ruby-graphviz
36
36
 
37
37
  Last (important) changes :
38
- * GraphViz#add_edge is deprecated, use GraphViz#add_edges
39
- * GraphViz#add_node is deprecated, use GraphViz#add_nodes
40
38
  * GraphViz::Edge#each_attribut is deprecated, use GraphViz::Edge#each_attribute
41
39
  * GraphViz::GraphML#attributs is deprecated, use GraphViz::GraphML#attributes
42
40
  * GraphViz::Node#each_attribut is deprecated, use GraphViz::Node#each_attribute
43
41
  }
44
42
 
45
43
  s.add_development_dependency 'rake'
46
- s.add_development_dependency 'gems'
47
44
  s.add_development_dependency 'rdoc'
48
- s.add_development_dependency 'minitest'
49
45
  s.add_development_dependency 'bundler'
50
- s.add_development_dependency 'ronn'
46
+ s.add_development_dependency 'ronn' unless RUBY_PLATFORM == 'java'
51
47
  end
@@ -0,0 +1,13 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'test/unit'
4
+ require 'pathname'
5
+
6
+ cur = Pathname.new(File.expand_path("..", __FILE__))
7
+ lib = cur.join('..', 'lib')
8
+
9
+ $LOAD_PATH.unshift(lib.to_s, cur.to_s)
10
+ require 'graphviz'
11
+ require 'graphviz/theory'
12
+ require 'graphviz/math/matrix'
13
+ require 'graphviz/utils/colors'
@@ -1,43 +1,47 @@
1
- require "minitest/autorun"
2
- require_relative "../lib/graphviz/dot_script"
3
-
4
- describe GraphViz::DOTScript do
5
- let(:script) { GraphViz::DOTScript.new }
6
-
7
- it "appends a newline character if it is missing" do
8
- str = "Test without newline"
9
- script.append(str)
10
- script.to_s.must_equal(str + "\n")
11
- end
12
-
13
- it "does not append a newline if already present" do
14
- str = "Linebreak follows at my tail:\n"
15
- script.append(str)
16
- script.to_s.must_equal(str)
17
- end
18
-
19
- it "can prepend lines to its content" do
20
- start_content = "I want to be at the top!\n"
21
- additional_content = "No way!\n"
22
-
23
- script.append(start_content)
24
- script.prepend(additional_content)
25
-
26
- script.to_s.must_equal(additional_content + start_content)
27
- end
28
-
29
- it "can add types with data" do
30
- data = "some random data"
31
- script.add_type("node_attr", data)
32
- script.to_s.must_match(/\s*node\s*\[\s*#{data}\s*\]\s*/m)
33
- end
34
-
35
- it "does nothing if data is empty" do
36
- script.add_type("anything", "")
37
- script.to_s.must_be :empty?
38
- end
39
-
40
- it "raises an argument error on unknown types" do
41
- -> { script.add_type("invalid", "some data") }.must_raise(ArgumentError)
1
+ require 'helper'
2
+
3
+ class GraphVizDOTScriptTest < Test::Unit::TestCase
4
+ def setup
5
+ @script = GraphViz::DOTScript.new
6
+ end
7
+
8
+ def test_appends_a_newline_character_if_it_is_missing
9
+ str = "Test without newline"
10
+ @script.append(str)
11
+ assert_equal @script.to_s, str + "\n"
12
+ end
13
+
14
+ def test_does_not_append_a_newline_if_already_present
15
+ str = "Linebreak follows at my tail:\n"
16
+ @script.append(str)
17
+ assert_equal @script.to_s, str
18
+ end
19
+
20
+ def test_can_prepend_lines_to_its_content
21
+ start_content = "I want to be at the top!\n"
22
+ additional_content = "No way!\n"
23
+
24
+ @script.append(start_content)
25
+ @script.prepend(additional_content)
26
+
27
+ assert_equal @script.to_s, additional_content + start_content
28
+ end
29
+
30
+ def test_can_add_types_with_data
31
+ data = "some random data"
32
+ @script.add_type("node_attr", data)
33
+ assert_match(/\s*node\s*\[\s*#{data}\s*\]\s*/, @script.to_s)
34
+ end
35
+
36
+ def test_does_nothing_if_data_is_empty
37
+ @script.add_type("anything", "")
38
+ assert_equal true, @script.to_s.empty?
39
+ end
40
+
41
+ def test_raises_an_argument_error_on_unknown_types
42
+ assert_raise ArgumentError do
43
+ @script.add_type("invalid", "some data")
42
44
  end
45
+ end
43
46
  end
47
+
@@ -1,35 +1,24 @@
1
- require File.expand_path('support.rb', File.dirname(__FILE__))
2
-
3
1
  class GraphVizTest < Test::Unit::TestCase
4
-
5
- #
6
2
  # you can run a subset of all the samples like this:
7
3
  # ruby test/test_examples.rb --name='/sample3[6-9]/'
8
4
  #
9
5
  # The above will run samples 36, 37, 38, and 39
10
6
  #
11
-
12
-
13
- include IoHack
14
-
15
7
  RootDir = File.expand_path('../..', __FILE__)
16
8
  ExampleDir = File.join(RootDir,'examples')
17
9
  OutputDir = File.join(File.dirname(__FILE__),'output')
18
- # OutputDir = File.join(RootDir,'test','output')
19
-
20
10
 
21
11
  # the below tests write to stdout. the other tests write to filesystem
22
-
23
12
  Skips = {
24
13
  #'35' => 'hanging for me',
25
14
  '33' => 'FamilyTree is broken',
26
15
  '36' => 'hangs for me',
27
16
  '53' => 'FamilyTree is broken',
28
17
  '57' => 'will not be able to find the graphml script',
18
+ '98' => 'This test is just for debug',
29
19
  '99' => 'FamilyTree is broken'
30
20
  }
31
21
 
32
-
33
22
  def test_sample07
34
23
  assert_output_pattern(/\Adigraph structs \{.+\}\n\Z/m, '07')
35
24
  end
@@ -66,6 +55,10 @@ class GraphVizTest < Test::Unit::TestCase
66
55
  assert_output_pattern(/\ANode.*\n\Z/m, '62')
67
56
  end
68
57
 
58
+ def test_sample70
59
+ assert_output_pattern(/\Agraph G \{.*\}\n\Z/m, '70')
60
+ end
61
+
69
62
  #
70
63
  # for every sample file in the examples directory that matches the
71
64
  # pattern ("sample01.rb, sample02.rb, etc) make a corresponding
@@ -99,31 +92,30 @@ class GraphVizTest < Test::Unit::TestCase
99
92
  attr_accessor :last_image_path, :number_to_path
100
93
  end
101
94
 
102
- samples = Dir[File.join(ExampleDir,'sample*.rb')].sort
95
+ if File.directory? OutputDir
96
+ FileUtils.rm_rf OutputDir
97
+ end
98
+ FileUtils.cp_r ExampleDir, OutputDir
99
+
100
+ samples = Dir[File.join(OutputDir,'sample*.rb')].sort
103
101
  samples.each {|path| make_sample_test_method(path) }
104
102
 
105
-
106
103
  private
107
104
 
108
105
  def assert_output_pattern tgt_regexp, number
109
106
  path = self.class.number_to_path[number]
110
- setup_sample path
111
- out, err = fake_popen2(path)
107
+ out, err, _ = Open3.capture3("ruby #{path}")
112
108
  assert_equal "", err, "no errors"
113
109
  assert_match tgt_regexp, out.gsub(/\r\n/, "\n"), "output for sample#{number} should match regexp"
114
110
  end
115
111
 
116
112
  def assert_sample_file_has_no_output path
117
- setup_sample(path)
118
113
  begin
119
- out, err = fake_popen2(path)
120
- assert_equal(0, out.length, "expecting empty output")
121
- assert_equal(0, err.length, "expecting empty errorput")
122
- msg = "maybe generated #{self.class.last_image_path}"
123
- print "\n", msg
114
+ out, err, _ = Open3.capture3("ruby #{path}")
115
+ assert_equal(0, out.length, "expecting empty output got [#{out}]")
116
+ assert_equal(0, err.length, "expecting empty errorput got [#{err}]")
124
117
  rescue Exception => e
125
118
  assert(false, "got exception on #{File.basename(path)}: #{e.message}")
126
- puts "out: ", out.inspect, "err:", err.inspect
127
119
  end
128
120
  end
129
121
 
@@ -132,14 +124,12 @@ private
132
124
  FileUtils.mkdir_p(OutputDir, :verbose => true)
133
125
  end
134
126
  ARGV[0] = nil if ARGV.any? # hack trigger searching for 'dot' executable
135
- hack_output_path path
136
127
  end
137
128
 
138
- def hack_output_path path
139
- # hack $0 to change where the output image is written to
140
- fake_example_path = File.join(OutputDir, File.basename(path))
141
- $program_name = fake_example_path.dup
142
- alias $0 $program_name
143
- self.class.last_image_path = "#{$0}.png"
129
+ def run_sample(path)
130
+ run_path = File.join(OutputDir, File.basename(path))
131
+ FileUtils.cp path, run_path
132
+ out, err, _ = Open3.capture3("ruby #{run_path}")
133
+ return out, err
144
134
  end
145
135
  end
@@ -1,6 +1,4 @@
1
- require 'test/unit'
2
- $:.unshift(File.expand_path('../../lib',__FILE__))
3
- require 'graphviz'
1
+ require 'helper'
4
2
 
5
3
  class GraphVizTest < Test::Unit::TestCase
6
4
  def setup
@@ -106,6 +104,19 @@ class GraphVizTest < Test::Unit::TestCase
106
104
  assert_nil c1.search_node("a0")
107
105
  end
108
106
 
107
+ def test_getting_escaped_node_from_edge
108
+ @g = GraphViz.graph "G" do |g|
109
+ g.add_nodes 'a@com'
110
+ g.add_nodes 'b@com'
111
+ g.add_edges 'a@com', 'b@com'
112
+ end
113
+
114
+ @g.each_edge do |e|
115
+ assert_not_nil @g.get_node e.node_one(true, false)
116
+ assert_not_nil @g.get_node e.node_two(true, false)
117
+ end
118
+ end
119
+
109
120
  def test_to_s
110
121
  assert_nothing_raised 'to_s with edge with numeric label failed.' do
111
122
  a = @graph.add_nodes('a')
@@ -1,7 +1,4 @@
1
- require 'test/unit'
2
- $:.unshift(File.expand_path('../../lib',__FILE__))
3
- require 'graphviz'
4
- require 'graphviz/theory'
1
+ require 'helper'
5
2
 
6
3
  class GraphVizSearch < Test::Unit::TestCase
7
4
  def setup
@@ -1,6 +1,4 @@
1
- require 'test/unit'
2
- $:.unshift(File.expand_path('../../lib',__FILE__))
3
- require 'graphviz'
1
+ require 'helper'
4
2
 
5
3
  class GraphVizSubGraphTest < Test::Unit::TestCase
6
4
  def test_subgraph
@@ -13,4 +11,17 @@ class GraphVizSubGraphTest < Test::Unit::TestCase
13
11
 
14
12
  assert_equal(master1.to_s, master2.to_s, "Wrong subgraph")
15
13
  end
14
+
15
+ def test_to_graph
16
+ m = GraphViz.new(:G)
17
+ m.add_edges("m1", "m2")
18
+ c = m.add_graph('c')
19
+ c.add_edges("c1", "c2")
20
+
21
+ assert_equal true, c.has_parent_graph?
22
+ assert_equal false, m.has_parent_graph?
23
+
24
+ ci = c.to_graph
25
+ assert_equal false, ci.has_parent_graph?
26
+ end
16
27
  end
@@ -1,8 +1,4 @@
1
- require 'test/unit'
2
- $:.unshift(File.expand_path('../../lib',__FILE__))
3
- require 'graphviz'
4
- require 'graphviz/theory'
5
- require 'graphviz/math/matrix'
1
+ require 'helper'
6
2
 
7
3
  class GraphVizTheoryTest < Test::Unit::TestCase
8
4
  def setup
@@ -99,4 +95,18 @@ class GraphVizTheoryTest < Test::Unit::TestCase
99
95
  assert_equal [1, 6], r[:path]
100
96
  assert_equal 6.0, r[:distance]
101
97
  end
98
+
99
+ def test_escaped_node_ids__adjancy_matrix
100
+ @g = GraphViz.graph "G" do |g|
101
+ g.add_nodes 'a@com'
102
+ g.add_nodes 'b@com'
103
+ g.add_edges 'a@com', 'b@com'
104
+ end
105
+
106
+ @t = GraphViz::Theory.new( @g )
107
+
108
+ assert_nothing_raised NoMethodError do
109
+ @t.adjancy_matrix
110
+ end
111
+ end
102
112
  end
@@ -1,6 +1,4 @@
1
- require 'test/unit'
2
- $:.unshift(File.expand_path('../../lib',__FILE__))
3
- require 'graphviz/types'
1
+ require 'helper'
4
2
 
5
3
  class TypesTest < Test::Unit::TestCase
6
4
  def test_gv_bool
@@ -1,6 +1,4 @@
1
- require 'test/unit'
2
- $:.unshift(File.expand_path('../../lib',__FILE__))
3
- require 'graphviz/utils/colors'
1
+ require 'helper'
4
2
 
5
3
  class TypesTest < Test::Unit::TestCase
6
4
  def setup
metadata CHANGED
@@ -1,97 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-graphviz
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregoire Lejeune
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-04-24 00:00:00.000000000 Z
11
+ date: 2014-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: gems
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '>='
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '>='
24
+ - - ">="
39
25
  - !ruby/object:Gem::Version
40
26
  version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rdoc
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - '>='
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - '>='
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: minitest
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - '>='
31
+ - - ">="
60
32
  - !ruby/object:Gem::Version
61
33
  version: '0'
62
34
  type: :development
63
35
  prerelease: false
64
36
  version_requirements: !ruby/object:Gem::Requirement
65
37
  requirements:
66
- - - '>='
38
+ - - ">="
67
39
  - !ruby/object:Gem::Version
68
40
  version: '0'
69
41
  - !ruby/object:Gem::Dependency
70
42
  name: bundler
71
43
  requirement: !ruby/object:Gem::Requirement
72
44
  requirements:
73
- - - '>='
45
+ - - ">="
74
46
  - !ruby/object:Gem::Version
75
47
  version: '0'
76
48
  type: :development
77
49
  prerelease: false
78
50
  version_requirements: !ruby/object:Gem::Requirement
79
51
  requirements:
80
- - - '>='
52
+ - - ">="
81
53
  - !ruby/object:Gem::Version
82
54
  version: '0'
83
55
  - !ruby/object:Gem::Dependency
84
56
  name: ronn
85
57
  requirement: !ruby/object:Gem::Requirement
86
58
  requirements:
87
- - - '>='
59
+ - - ">="
88
60
  - !ruby/object:Gem::Version
89
61
  version: '0'
90
62
  type: :development
91
63
  prerelease: false
92
64
  version_requirements: !ruby/object:Gem::Requirement
93
65
  requirements:
94
- - - '>='
66
+ - - ">="
95
67
  - !ruby/object:Gem::Version
96
68
  version: '0'
97
69
  description: Ruby/Graphviz provides an interface to layout and generate images of
@@ -110,9 +82,9 @@ extra_rdoc_files:
110
82
  - AUTHORS.rdoc
111
83
  - CHANGELOG.rdoc
112
84
  files:
113
- - .gemrc
114
- - .gitignore
115
- - .travis.yml
85
+ - ".gemrc"
86
+ - ".gitignore"
87
+ - ".travis.yml"
116
88
  - AUTHORS.rdoc
117
89
  - CHANGELOG.rdoc
118
90
  - COPYING.rdoc
@@ -225,6 +197,9 @@ files:
225
197
  - examples/sample67.rb
226
198
  - examples/sample68.rb
227
199
  - examples/sample69.rb
200
+ - examples/sample70.rb
201
+ - examples/sample71.rb
202
+ - examples/sample72.rb
228
203
  - examples/sample99.rb
229
204
  - examples/sdlshapes/README
230
205
  - examples/sdlshapes/sdl.ps
@@ -281,7 +256,7 @@ files:
281
256
  - man/xml2gv.1.ronn
282
257
  - ruby-graphviz.gemspec
283
258
  - setup.rb
284
- - test/support.rb
259
+ - test/helper.rb
285
260
  - test/test_dot_script.rb
286
261
  - test/test_examples.rb
287
262
  - test/test_graph.rb
@@ -298,36 +273,34 @@ post_install_message: "\nSince version 0.9.2, Ruby/GraphViz can use Open3.popen3
298
273
  (http://graphviz.org/) to use this Gem.\n\nFor more information about Ruby-Graphviz
299
274
  :\n* Doc : http://rdoc.info/projects/glejeune/Ruby-Graphviz\n* Sources : http://github.com/glejeune/Ruby-Graphviz\n*
300
275
  NEW - Mailing List : http://groups.google.com/group/ruby-graphviz\n\nLast (important)
301
- changes :\n* GraphViz#add_edge is deprecated, use GraphViz#add_edges\n* GraphViz#add_node
302
- is deprecated, use GraphViz#add_nodes\n* GraphViz::Edge#each_attribut is deprecated,
303
- use GraphViz::Edge#each_attribute\n* GraphViz::GraphML#attributs is deprecated,
304
- use GraphViz::GraphML#attributes\n* GraphViz::Node#each_attribut is deprecated,
305
- use GraphViz::Node#each_attribute\n "
276
+ changes :\n* GraphViz::Edge#each_attribut is deprecated, use GraphViz::Edge#each_attribute\n*
277
+ GraphViz::GraphML#attributs is deprecated, use GraphViz::GraphML#attributes\n* GraphViz::Node#each_attribut
278
+ is deprecated, use GraphViz::Node#each_attribute\n "
306
279
  rdoc_options:
307
- - --title
280
+ - "--title"
308
281
  - Ruby/GraphViz
309
- - --main
282
+ - "--main"
310
283
  - README.rdoc
311
284
  require_paths:
312
285
  - lib
313
286
  required_ruby_version: !ruby/object:Gem::Requirement
314
287
  requirements:
315
- - - '>='
288
+ - - ">="
316
289
  - !ruby/object:Gem::Version
317
290
  version: '0'
318
291
  required_rubygems_version: !ruby/object:Gem::Requirement
319
292
  requirements:
320
- - - '>='
293
+ - - ">="
321
294
  - !ruby/object:Gem::Version
322
295
  version: '0'
323
296
  requirements: []
324
297
  rubyforge_project: ruby-asp
325
- rubygems_version: 2.0.3
298
+ rubygems_version: 2.2.1
326
299
  signing_key:
327
300
  specification_version: 4
328
301
  summary: Interface to the GraphViz graphing tool
329
302
  test_files:
330
- - test/support.rb
303
+ - test/helper.rb
331
304
  - test/test_dot_script.rb
332
305
  - test/test_examples.rb
333
306
  - test/test_graph.rb