ul-wukong 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (261) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +60 -0
  3. data/.gitmodules +6 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +19 -0
  6. data/.yardopts +6 -0
  7. data/CHANGELOG.md +7 -0
  8. data/Gemfile +17 -0
  9. data/Guardfile +12 -0
  10. data/LICENSE.md +95 -0
  11. data/NOTES-travis.md +31 -0
  12. data/README-old.md +422 -0
  13. data/README.md +1308 -0
  14. data/Rakefile +28 -0
  15. data/TODO.md +99 -0
  16. data/bin/cutc +30 -0
  17. data/bin/cuttab +5 -0
  18. data/bin/greptrue +6 -0
  19. data/bin/md5sort +20 -0
  20. data/bin/setcat +11 -0
  21. data/bin/tabchar +5 -0
  22. data/bin/uniq-ord +59 -0
  23. data/bin/uniqc +3 -0
  24. data/bin/wu +34 -0
  25. data/bin/wu-clean-encoding +31 -0
  26. data/bin/wu-date +13 -0
  27. data/bin/wu-datetime +13 -0
  28. data/bin/wu-hist +3 -0
  29. data/bin/wu-lign +186 -0
  30. data/bin/wu-local +4 -0
  31. data/bin/wu-plus +9 -0
  32. data/bin/wu-source +5 -0
  33. data/bin/wu-sum +31 -0
  34. data/diagrams/wu_local.dot +39 -0
  35. data/diagrams/wu_local.dot.png +0 -0
  36. data/examples/Gemfile +38 -0
  37. data/examples/README.md +9 -0
  38. data/examples/basic/string_reverser.rb +23 -0
  39. data/examples/basic/tiny_count.rb +8 -0
  40. data/examples/basic/word_count/accumulator.rb +26 -0
  41. data/examples/basic/word_count/tokenizer.rb +13 -0
  42. data/examples/basic/word_count/word_count.rb +6 -0
  43. data/examples/dataflow/scraper_macro_flow.rb +28 -0
  44. data/examples/deploy_pack/Gemfile +6 -0
  45. data/examples/deploy_pack/README.md +6 -0
  46. data/examples/deploy_pack/a/b/c/.gitkeep +0 -0
  47. data/examples/deploy_pack/app/processors/string_reverser.rb +5 -0
  48. data/examples/deploy_pack/config/environment.rb +1 -0
  49. data/examples/dsl/dataflow/fibonacci_series.rb +101 -0
  50. data/examples/dsl/dataflow/scraper_macro_flow.rb +28 -0
  51. data/examples/dsl/dataflow/simple.rb +12 -0
  52. data/examples/dsl/dataflow/telegram.rb +45 -0
  53. data/examples/dsl/workflow/cherry_pie.dot +97 -0
  54. data/examples/dsl/workflow/cherry_pie.md +104 -0
  55. data/examples/dsl/workflow/cherry_pie.png +0 -0
  56. data/examples/dsl/workflow/cherry_pie.rb +101 -0
  57. data/examples/empty/.gitkeep +0 -0
  58. data/examples/examples_helper.rb +9 -0
  59. data/examples/geo.rb +4 -0
  60. data/examples/geo/geo_grids.numbers +0 -0
  61. data/examples/geo/geolocated.rb +331 -0
  62. data/examples/geo/quadtile.rb +69 -0
  63. data/examples/geo/spec/geolocated_spec.rb +247 -0
  64. data/examples/geo/tile_fetcher.rb +77 -0
  65. data/examples/graph/implied_geolocation/README.md +63 -0
  66. data/examples/graph/minimum_spanning_tree/airfares_graphviz.rb +73 -0
  67. data/examples/improver/tweet_summary.rb +73 -0
  68. data/examples/loadable.rb +2 -0
  69. data/examples/munging/airline_flights/airline_flights.rake +83 -0
  70. data/examples/munging/airline_flights/airplane.rb +0 -0
  71. data/examples/munging/airline_flights/airport_id_unification.rb +129 -0
  72. data/examples/munging/airline_flights/airport_ok_chars.rb +4 -0
  73. data/examples/munging/airline_flights/indexable.rb +75 -0
  74. data/examples/munging/airline_flights/indexable_spec.rb +90 -0
  75. data/examples/munging/airline_flights/reconcile_airports.rb +142 -0
  76. data/examples/munging/airline_flights/tasks.rake +83 -0
  77. data/examples/munging/airline_flights/topcities.rb +167 -0
  78. data/examples/munging/geo/geo_json.rb +54 -0
  79. data/examples/munging/geo/geo_models.rb +69 -0
  80. data/examples/munging/geo/geonames_models.rb +107 -0
  81. data/examples/munging/geo/iso_codes.rb +172 -0
  82. data/examples/munging/geo/reconcile_countries.rb +124 -0
  83. data/examples/munging/geo/tasks.rake +71 -0
  84. data/examples/munging/wikipedia/articles/extract_articles-parsed.rb +79 -0
  85. data/examples/munging/wikipedia/articles/extract_articles-templated.rb +136 -0
  86. data/examples/munging/wikipedia/articles/textualize_articles.rb +54 -0
  87. data/examples/munging/wikipedia/articles/verify_structure.rb +43 -0
  88. data/examples/munging/wikipedia/articles/wp2txt-LICENSE.txt +22 -0
  89. data/examples/munging/wikipedia/articles/wp2txt_article.rb +259 -0
  90. data/examples/munging/wikipedia/articles/wp2txt_utils.rb +452 -0
  91. data/examples/munging/wikipedia/dbpedia/dbpedia_common.rb +5 -0
  92. data/examples/munging/wikipedia/dbpedia/dbpedia_extract_geocoordinates.rb +78 -0
  93. data/examples/munging/wikipedia/dbpedia/extract_links-cruft.rb +66 -0
  94. data/examples/munging/wikipedia/dbpedia/extract_links.rb +260 -0
  95. data/examples/munging/wikipedia/dbpedia/sameas_extractor.rb +20 -0
  96. data/examples/rake_helper.rb +97 -0
  97. data/examples/ruby_project/Gemfile +6 -0
  98. data/examples/ruby_project/README.md +6 -0
  99. data/examples/ruby_project/a/b/c/.gitkeep +0 -0
  100. data/examples/server_logs/geo_ip_mapping/munge_geolite.rb +82 -0
  101. data/examples/server_logs/logline.rb +95 -0
  102. data/examples/server_logs/models.rb +66 -0
  103. data/examples/server_logs/page_counts.pig +48 -0
  104. data/examples/server_logs/server_logs-01-parse-script.rb +13 -0
  105. data/examples/server_logs/server_logs-02-histograms-full.rb +33 -0
  106. data/examples/server_logs/server_logs-02-histograms-mapper.rb +14 -0
  107. data/examples/server_logs/server_logs-03-breadcrumbs-full.rb +71 -0
  108. data/examples/server_logs/server_logs-04-page_page_edges-full.rb +40 -0
  109. data/examples/serverlogs/geo_ip_mapping/munge_geolite.rb +82 -0
  110. data/examples/serverlogs/models/logline.rb +102 -0
  111. data/examples/serverlogs/parser/apache_parser_widget.rb +46 -0
  112. data/examples/serverlogs/visit_paths/common.rb +4 -0
  113. data/examples/serverlogs/visit_paths/page_counts.pig +48 -0
  114. data/examples/serverlogs/visit_paths/serverlogs-01-parse-script.rb +11 -0
  115. data/examples/serverlogs/visit_paths/serverlogs-02-histograms-full.rb +31 -0
  116. data/examples/serverlogs/visit_paths/serverlogs-02-histograms-mapper.rb +12 -0
  117. data/examples/serverlogs/visit_paths/serverlogs-03-breadcrumbs-full.rb +67 -0
  118. data/examples/serverlogs/visit_paths/serverlogs-04-page_page_edges-full.rb +38 -0
  119. data/examples/splitter.rb +94 -0
  120. data/examples/string_reverser.rb +7 -0
  121. data/examples/text/pig_latin/pig_latinizer.rb +35 -0
  122. data/examples/text/pig_latin/pig_latinizer_widget.rb +16 -0
  123. data/examples/text/regional_flavor/README.md +14 -0
  124. data/examples/text/regional_flavor/article_wordbags.pig +39 -0
  125. data/examples/text/regional_flavor/j01-article_wordbags.rb +4 -0
  126. data/examples/text/regional_flavor/simple_pig_script.pig +27 -0
  127. data/examples/twitter.rb +5 -0
  128. data/lib/hanuman.rb +36 -0
  129. data/lib/hanuman/graph.rb +97 -0
  130. data/lib/hanuman/graphvizzer.rb +206 -0
  131. data/lib/hanuman/graphvizzer/gv_models.rb +161 -0
  132. data/lib/hanuman/graphvizzer/gv_presenter.rb +97 -0
  133. data/lib/hanuman/link.rb +35 -0
  134. data/lib/hanuman/registry.rb +46 -0
  135. data/lib/hanuman/stage.rb +128 -0
  136. data/lib/hanuman/tree.rb +67 -0
  137. data/lib/wu/geo.rb +4 -0
  138. data/lib/wu/geo/geo_grids.numbers +0 -0
  139. data/lib/wu/geo/geolocated.rb +331 -0
  140. data/lib/wu/geo/quadtile.rb +69 -0
  141. data/lib/wu/graph/union_find.rb +62 -0
  142. data/lib/wu/model/reconcilable.rb +63 -0
  143. data/lib/wu/munging.rb +71 -0
  144. data/lib/wu/social/models/twitter.rb +31 -0
  145. data/lib/wu/wikipedia/models.rb +20 -0
  146. data/lib/wukong.rb +54 -0
  147. data/lib/wukong/dataflow.rb +43 -0
  148. data/lib/wukong/doc_helpers.rb +14 -0
  149. data/lib/wukong/doc_helpers/dataflow_handler.rb +29 -0
  150. data/lib/wukong/doc_helpers/field_handler.rb +91 -0
  151. data/lib/wukong/doc_helpers/processor_handler.rb +29 -0
  152. data/lib/wukong/driver.rb +214 -0
  153. data/lib/wukong/driver/event_machine_driver.rb +15 -0
  154. data/lib/wukong/driver/wiring.rb +68 -0
  155. data/lib/wukong/local.rb +42 -0
  156. data/lib/wukong/local/runner.rb +96 -0
  157. data/lib/wukong/local/stdio_driver.rb +104 -0
  158. data/lib/wukong/logger.rb +102 -0
  159. data/lib/wukong/model/faker.rb +136 -0
  160. data/lib/wukong/model/flatpack_parser/flat.rb +60 -0
  161. data/lib/wukong/model/flatpack_parser/flatpack.rb +4 -0
  162. data/lib/wukong/model/flatpack_parser/lang.rb +46 -0
  163. data/lib/wukong/model/flatpack_parser/parser.rb +55 -0
  164. data/lib/wukong/model/flatpack_parser/tokens.rb +130 -0
  165. data/lib/wukong/plugin.rb +48 -0
  166. data/lib/wukong/processor.rb +110 -0
  167. data/lib/wukong/rake_helper.rb +6 -0
  168. data/lib/wukong/runner.rb +169 -0
  169. data/lib/wukong/runner/boot_sequence.rb +123 -0
  170. data/lib/wukong/runner/code_loader.rb +52 -0
  171. data/lib/wukong/runner/command_runner.rb +44 -0
  172. data/lib/wukong/runner/deploy_pack_loader.rb +75 -0
  173. data/lib/wukong/runner/help_message.rb +42 -0
  174. data/lib/wukong/source.rb +33 -0
  175. data/lib/wukong/source/source_driver.rb +74 -0
  176. data/lib/wukong/source/source_runner.rb +38 -0
  177. data/lib/wukong/spec_helpers.rb +74 -0
  178. data/lib/wukong/spec_helpers/integration_tests.rb +150 -0
  179. data/lib/wukong/spec_helpers/integration_tests/integration_test_matchers.rb +207 -0
  180. data/lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb +97 -0
  181. data/lib/wukong/spec_helpers/shared_examples.rb +22 -0
  182. data/lib/wukong/spec_helpers/unit_tests.rb +135 -0
  183. data/lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb +132 -0
  184. data/lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb +169 -0
  185. data/lib/wukong/spec_helpers/unit_tests/unit_test_runner.rb +60 -0
  186. data/lib/wukong/version.rb +3 -0
  187. data/lib/wukong/widget/echo.rb +55 -0
  188. data/lib/wukong/widget/extract.rb +122 -0
  189. data/lib/wukong/widget/filters.rb +452 -0
  190. data/lib/wukong/widget/logger.rb +56 -0
  191. data/lib/wukong/widget/operators.rb +82 -0
  192. data/lib/wukong/widget/reducers.rb +10 -0
  193. data/lib/wukong/widget/reducers/accumulator.rb +73 -0
  194. data/lib/wukong/widget/reducers/bin.rb +368 -0
  195. data/lib/wukong/widget/reducers/count.rb +73 -0
  196. data/lib/wukong/widget/reducers/group.rb +128 -0
  197. data/lib/wukong/widget/reducers/group_concat.rb +98 -0
  198. data/lib/wukong/widget/reducers/improver.rb +71 -0
  199. data/lib/wukong/widget/reducers/join_xml.rb +37 -0
  200. data/lib/wukong/widget/reducers/moments.rb +72 -0
  201. data/lib/wukong/widget/reducers/sort.rb +180 -0
  202. data/lib/wukong/widget/reducers/uniq.rb +91 -0
  203. data/lib/wukong/widget/serializers.rb +317 -0
  204. data/lib/wukong/widget/utils.rb +46 -0
  205. data/lib/wukong/widgets.rb +7 -0
  206. data/spec/examples/dataflow/fibonacci_series_spec.rb +18 -0
  207. data/spec/examples/dataflow/parse_apache_logs_spec.rb +8 -0
  208. data/spec/examples/dataflow/parsing_spec.rb +14 -0
  209. data/spec/examples/dataflow/simple_spec.rb +34 -0
  210. data/spec/examples/dataflow/telegram_spec.rb +43 -0
  211. data/spec/examples/graph/minimum_spanning_tree_spec.rb +34 -0
  212. data/spec/examples/munging/airline_flights/identifiers_spec.rb +16 -0
  213. data/spec/examples/munging/airline_flights_spec.rb +202 -0
  214. data/spec/examples/text/pig_latin_spec.rb +18 -0
  215. data/spec/examples/workflow/cherry_pie_spec.rb +36 -0
  216. data/spec/hanuman/graph_spec.rb +119 -0
  217. data/spec/hanuman/hanuman_spec.rb +10 -0
  218. data/spec/hanuman/registry_spec.rb +123 -0
  219. data/spec/hanuman/stage_spec.rb +81 -0
  220. data/spec/hanuman/tree_spec.rb +119 -0
  221. data/spec/spec.opts +1 -0
  222. data/spec/spec_helper.rb +43 -0
  223. data/spec/support/example_test_helpers.rb +95 -0
  224. data/spec/support/hanuman_test_helpers.rb +92 -0
  225. data/spec/support/integration_helper.rb +38 -0
  226. data/spec/support/model_test_helpers.rb +115 -0
  227. data/spec/support/shared_context_for_graphs.rb +57 -0
  228. data/spec/support/shared_context_for_reducers.rb +37 -0
  229. data/spec/support/shared_examples_for_builders.rb +94 -0
  230. data/spec/support/shared_examples_for_shortcuts.rb +57 -0
  231. data/spec/wu/model/reconcilable_spec.rb +152 -0
  232. data/spec/wukong/dataflow_spec.rb +87 -0
  233. data/spec/wukong/driver_spec.rb +154 -0
  234. data/spec/wukong/local/runner_spec.rb +29 -0
  235. data/spec/wukong/local/stdio_driver_spec.rb +73 -0
  236. data/spec/wukong/local_spec.rb +6 -0
  237. data/spec/wukong/logger_spec.rb +49 -0
  238. data/spec/wukong/model/faker_spec.rb +132 -0
  239. data/spec/wukong/processor_spec.rb +21 -0
  240. data/spec/wukong/runner_spec.rb +132 -0
  241. data/spec/wukong/source_spec.rb +6 -0
  242. data/spec/wukong/widget/extract_spec.rb +101 -0
  243. data/spec/wukong/widget/filters_spec.rb +79 -0
  244. data/spec/wukong/widget/logger_spec.rb +23 -0
  245. data/spec/wukong/widget/operators_spec.rb +25 -0
  246. data/spec/wukong/widget/reducers/bin_spec.rb +92 -0
  247. data/spec/wukong/widget/reducers/count_spec.rb +11 -0
  248. data/spec/wukong/widget/reducers/group_spec.rb +21 -0
  249. data/spec/wukong/widget/reducers/join_xml_spec.rb +25 -0
  250. data/spec/wukong/widget/reducers/moments_spec.rb +36 -0
  251. data/spec/wukong/widget/reducers/sort_spec.rb +26 -0
  252. data/spec/wukong/widget/reducers/uniq_spec.rb +14 -0
  253. data/spec/wukong/widget/serializers_spec.rb +114 -0
  254. data/spec/wukong/widget/sink_spec.rb +19 -0
  255. data/spec/wukong/widget/source_spec.rb +65 -0
  256. data/spec/wukong/wu-local_spec.rb +109 -0
  257. data/spec/wukong/wu-source_spec.rb +32 -0
  258. data/spec/wukong/wu_spec.rb +14 -0
  259. data/spec/wukong/wukong_spec.rb +10 -0
  260. data/wukong.gemspec +35 -0
  261. metadata +465 -0
@@ -0,0 +1 @@
1
+ --color
@@ -0,0 +1,43 @@
1
+ require 'wukong'
2
+ require 'wukong/spec_helpers'
3
+ require 'wukong/source'
4
+ require_relative './support/shared_context_for_graphs'
5
+ require_relative './support/shared_examples_for_shortcuts'
6
+ require_relative './support/shared_examples_for_builders'
7
+ require_relative './support/shared_context_for_reducers'
8
+
9
+ RSpec.configure do |config|
10
+
11
+ config.mock_with :rspec
12
+
13
+ include Wukong::SpecHelpers
14
+ def root
15
+ @root ||= Pathname.new(File.expand_path('../..', __FILE__))
16
+ end
17
+
18
+ def local_runner *args
19
+ runner(Wukong::Local::LocalRunner, 'wu-local', *args)
20
+ end
21
+
22
+ def generic_runner *args
23
+ # the wu-generic program doesn't have to exist for this Runner to
24
+ # work if it's called from Ruby code
25
+ runner(Wukong::Runner, 'wu-generic', *args)
26
+ end
27
+
28
+ def wu_local *args
29
+ command('wu-local', *args)
30
+ end
31
+
32
+ def wu_source *args
33
+ command('wu-source', *args)
34
+ end
35
+
36
+ def wu *args
37
+ command('wu', *args)
38
+ end
39
+
40
+ # FIXME Why is this here?
41
+ config.treat_symbols_as_metadata_keys_with_true_values = true
42
+
43
+ end
@@ -0,0 +1,95 @@
1
+ if ENV['WUKONG_COV']
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter '/gorillib/'
5
+ add_filter '/away/'
6
+ add_group 'Hanuman', '/hanuman/'
7
+ end
8
+ end
9
+
10
+ require 'gorillib/pathname'
11
+ require 'gorillib/type/extended'
12
+ require 'wukong/model/faker'
13
+
14
+ Pathname.register_path(:wukong_root, File.expand_path('..', File.dirname(__FILE__)))
15
+ Pathname.register_path(:examples, :wukong_root, 'examples')
16
+ Pathname.register_path(:tmp, :wukong_root, 'tmp')
17
+ Pathname.register_path(:data, :wukong_root, 'data')
18
+ Pathname.path_to(:tmp).mkpath
19
+
20
+ Dir[ Pathname.path_to('spec', 'support', '*.rb') ].each{|f| require f }
21
+
22
+ result = `dot -V 2>&1` rescue nil
23
+ GRAPHVIZ = ($?.exitstatus == 0) && (result =~ /dot - graphviz version/)
24
+ puts 'Some specs require graphviz to run -- brew/apt install graphviz, it is pretty awesome' unless GRAPHVIZ
25
+
26
+ RSpec.configure do |config|
27
+ config.treat_symbols_as_metadata_keys_with_true_values = true
28
+ end
29
+
30
+ shared_context 'wukong', :helpers => true do
31
+ RSpec::Matchers.define(:be_in){|expected| match{|actual| expected.include?(actual) } }
32
+
33
+ def self.be_ish_matcher(handle, regexp)
34
+ RSpec::Matchers.define("be_#{handle}_ish"){ match{|actual| actual.should =~ regexp } }
35
+ end
36
+
37
+ let(:mock_val) { mock('mock val') }
38
+ let(:mock_record) { mock('mock record') }
39
+ let(:mock_stage) { mock('mock stage') }
40
+ let(:mock_processor){ mock('mock processor') }
41
+
42
+ let(:test_source) { Wukong::Integers.new(:name => :integers, :qty => 100) }
43
+ let(:test_sink) { Wukong::Sink::ArraySink.new(:name => :test_sink) }
44
+ let(:test_processor_class){ Wukong::AsIs }
45
+ let(:test_processor) { test_processor_class.new }
46
+ let(:test_filter) { Wukong::Widget::RegexpFilter.new(:re => /^m/) }
47
+ let(:test_dataflow) { Wukong.dataflow(:test_dataflow) }
48
+ end
49
+
50
+ require 'gorillib/utils/capture_output'
51
+
52
+ module WukongTestHelpers
53
+
54
+ def example_script_filename(name)
55
+ Pathname.path_to(:examples, name)
56
+ end
57
+
58
+ def example_script_contents(name)
59
+ File.read(example_script_filename(name))
60
+ end
61
+
62
+ def sample_data_filename(name)
63
+ Pathname.path_to(:wukong_root, 'data', name)
64
+ end
65
+
66
+ def sample_data(name)
67
+ File.open(sample_data_filename(name))
68
+ end
69
+
70
+ end
71
+
72
+ RSpec::Core::DSL.module_eval do
73
+ def describe_example_script(example_name, source_file, attrs={}, &block)
74
+ return unless attrs[:only]
75
+ load Pathname.path_to(:examples, source_file)
76
+ describe "Example: #{example_name}", attrs.merge(:examples_spec => true, :helpers => true) do
77
+ let(:example_name){ example_name }
78
+ instance_eval(&block)
79
+ end
80
+ rescue StandardError => err
81
+ warn "Broken example #{example_name} with script #{source_file} (#{attrs})"
82
+ warn err
83
+ warn err.backtrace.join("\n")
84
+ end
85
+
86
+ def it_generates_graphviz
87
+ it 'generates a graphviz picture', :if => GRAPHVIZ do
88
+ require 'hanuman/graphvizzer/gv_presenter'
89
+ #
90
+ basename = Pathname.path_to(:tmp, example_name.to_s)
91
+ Wukong.to_graphviz.save(basename, 'png')
92
+ yield "#{basename}.dot" if block_given?
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,92 @@
1
+ require 'gorillib/utils/capture_output'
2
+
3
+ shared_context 'hanuman', :helpers => true do
4
+ let(:test_stage){ Hanuman::Stage.new(:name => :testy) }
5
+
6
+ let :example_graph do
7
+ Hanuman::Graph.new(:name => :scraper) do
8
+ action(:listener) << product(:scrape_requests) << product(:more_requests)
9
+ action(:parser).input(:listener)
10
+ action(:models).input(:parser)
11
+ end
12
+ end
13
+
14
+ end
15
+
16
+ shared_examples_for 'it can be linked into' do
17
+ let(:mock_slot){ mock('mock slot') }
18
+ before do
19
+ mock_dataflow.stub(:connect).with(mock_slot, :default, subject, :default).and_return([mock_slot, subject])
20
+ subject.write_attribute(:owner, mock_dataflow)
21
+ end
22
+
23
+ context '#<<' do
24
+ it 'delegates to from' do
25
+ subject.should_receive(:from).with(mock_slot)
26
+ subject << mock_slot
27
+ end
28
+ it 'returns the stage itself, for chaining' do
29
+ (subject << mock_slot).should == subject
30
+ end
31
+ end
32
+
33
+ context '#from' do
34
+ it 'asks its owner to register an edge from self into given stage' do
35
+ mock_dataflow.should_receive(:connect).with(mock_slot, :default, subject, :default)
36
+ subject.from mock_slot
37
+ end
38
+ it 'returns the stage itself, for chaining' do
39
+ subject.from(mock_slot).should == subject
40
+ end
41
+ end
42
+
43
+ context 'set_sink' do
44
+ it 'returns the actual receiving slot' do
45
+ # subject.set_sink(:default, mock_stage).should equal(subject)
46
+ subject.set_sink(mock_stage).should equal(subject)
47
+ end
48
+ it 'sets the output attribute' do
49
+ subject.should_receive(:write_attribute).with(:output, mock_stage)
50
+ # subject.set_sink(:default, mock_stage)
51
+ subject.set_sink(mock_stage)
52
+ end
53
+ end
54
+ end
55
+
56
+ shared_examples_for 'it can be linked from' do
57
+ let(:mock_slot){ mock('mock slot') }
58
+ before do
59
+ mock_dataflow.stub(:connect).with(subject, :default, mock_slot, :default).and_return([subject, mock_slot])
60
+ subject.write_attribute(:owner, mock_dataflow)
61
+ end
62
+
63
+ context '#>' do
64
+ it 'asks its owner to register an edge into self from given stage' do
65
+ mock_dataflow.should_receive(:connect).with(subject, :default, mock_slot, :default)
66
+ subject.into mock_slot
67
+ end
68
+ it 'returns the output stage' do
69
+ (subject > mock_slot).should == mock_slot
70
+ end
71
+ end
72
+
73
+ context '#into' do
74
+ it 'asks its owner to register an edge into self from given stage' do
75
+ mock_dataflow.should_receive(:connect).with(subject, :default, mock_slot, :default)
76
+ subject.into mock_slot
77
+ end
78
+ it 'returns the stage itself, for chaining' do
79
+ subject.into(mock_slot).should == subject
80
+ end
81
+ end
82
+
83
+ context 'set_input' do
84
+ it 'returns the actual receiving slot' do
85
+ subject.set_source(mock_stage).should equal(subject)
86
+ end
87
+ it 'sets the input attribute' do
88
+ subject.should_receive(:write_attribute).with(:input, mock_stage)
89
+ subject.set_source(mock_stage)
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,38 @@
1
+ module Wukong
2
+ module Local
3
+ module IntegrationHelper
4
+
5
+ def root
6
+ @root ||= Pathname.new(File.expand_path('../../..', __FILE__))
7
+ end
8
+
9
+ def lib_dir *args
10
+ root.join('lib', *args)
11
+ end
12
+
13
+ def bin_dir *args
14
+ root.join('bin', *args)
15
+ end
16
+
17
+ def examples_dir *args
18
+ root.join('examples', *args)
19
+ end
20
+
21
+ def integration_env
22
+ {
23
+ "PATH" => [bin_dir.to_s, ENV["PATH"]].compact.join(':'),
24
+ "RUBYLIB" => [lib_dir.to_s, ENV["RUBYLIB"]].compact.join(':')
25
+ }
26
+ end
27
+
28
+ def integration_cwd
29
+ root.to_s
30
+ end
31
+
32
+ def example_script *args
33
+ examples_dir(*args)
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,115 @@
1
+ require 'gorillib/utils/nuke_constants'
2
+ require 'gorillib/utils/capture_output'
3
+
4
+ module Gorillib ; module Test ; end ; end
5
+ module Meta ; module Gorillib ; module Test ; end ; end ; end
6
+
7
+ shared_context 'model', :model_spec do
8
+ include Gorillib::TestHelpers
9
+
10
+ after(:each){ Gorillib::Test.nuke_constants ; Meta::Gorillib::Test.nuke_constants }
11
+
12
+ let(:mock_val){ double('mock value') }
13
+
14
+ let(:smurf_class) do
15
+ class Gorillib::Test::Smurf
16
+ include Gorillib::Model
17
+ field :name, String
18
+ field :smurfiness, Integer
19
+ field :weapon, Symbol
20
+ end
21
+ Gorillib::Test::Smurf
22
+ end
23
+ let(:papa_smurf ){ smurf_class.receive(:name => 'Papa Smurf', :smurfiness => 9, :weapon => 'staff') }
24
+ let(:smurfette ){ smurf_class.receive(:name => 'Smurfette', :smurfiness => 11, :weapon => 'charm') }
25
+
26
+ let(:smurf_collection_class) do
27
+ smurf_class
28
+ class Gorillib::Test::SmurfCollection < Gorillib::ModelCollection
29
+ include Gorillib::Collection::ItemsBelongTo
30
+ self.item_type = Gorillib::Test::Smurf
31
+ self.parentage_method = :village
32
+ end
33
+ Gorillib::Test::SmurfCollection
34
+ end
35
+
36
+ let(:smurf_village_class) do
37
+ smurf_class ; smurf_collection_class
38
+ module Gorillib::Test
39
+ class SmurfVillage
40
+ include Gorillib::Model
41
+ field :name, Symbol
42
+ collection :smurfs, SmurfCollection, item_type: Smurf, key_method: :name
43
+ end
44
+ end
45
+ Gorillib::Test::SmurfVillage
46
+ end
47
+
48
+ let(:smurfhouse_class) do
49
+ module Gorillib::Test
50
+ class Smurfhouse
51
+ include Gorillib::Model
52
+ field :shape, Symbol
53
+ field :color, Symbol
54
+ end
55
+ end
56
+ Gorillib::Test::Smurfhouse
57
+ end
58
+
59
+ end
60
+
61
+ shared_context 'builder', :model_spec, :builder_spec do
62
+ let(:engine_class) do
63
+ class Gorillib::Test::Engine
64
+ include Gorillib::Builder
65
+ magic :name, Symbol, :default => ->{ "#{owner? ? owner.name : ''} engine"}
66
+ magic :carburetor, Symbol, :default => :stock
67
+ magic :volume, Integer, :doc => 'displacement volume, in in^3'
68
+ magic :cylinders, Integer
69
+ member :owner, Whatever
70
+ self
71
+ end
72
+ Gorillib::Test::Engine
73
+ end
74
+
75
+ let(:car_class) do
76
+ engine_class
77
+ class Gorillib::Test::Car
78
+ include Gorillib::Builder
79
+ magic :name, Symbol
80
+ magic :make_model, String
81
+ magic :year, Integer
82
+ magic :doors, Integer
83
+ member :engine, Gorillib::Test::Engine
84
+ self
85
+ end
86
+ Gorillib::Test::Car
87
+ end
88
+
89
+ let(:garage_class) do
90
+ car_class
91
+ class Gorillib::Test::Garage
92
+ include Gorillib::Builder
93
+ collection :cars, Gorillib::Test::Car, key_method: :name
94
+ self
95
+ end
96
+ Gorillib::Test::Garage
97
+ end
98
+
99
+ let(:wildcat) do
100
+ car_class.receive( :name => :wildcat,
101
+ :make_model => 'Buick Wildcat', :year => 1968, :doors => 2,
102
+ :engine => { :volume => 455, :cylinders => 8 } )
103
+ end
104
+ let(:ford_39) do
105
+ car_class.receive( :name => :ford_39,
106
+ :make_model => 'Ford Tudor Sedan', :year => 1939, :doors => 2, )
107
+ end
108
+ let(:garage) do
109
+ garage_class.new
110
+ end
111
+ let(:example_engine) do
112
+ engine_class.new( :name => 'Geo Metro 1.0L', :volume => 61, :cylinders => 3 )
113
+ end
114
+
115
+ end
@@ -0,0 +1,57 @@
1
+ shared_context "graphs" do
2
+
3
+ let(:empty_graph) do
4
+ Hanuman::Graph.receive({})
5
+ end
6
+
7
+ let(:single_stage_graph) do
8
+ Hanuman::Graph.receive({stages: {first: Hanuman::Stage.receive(label: :first)}})
9
+ end
10
+
11
+ let(:graph) do
12
+ Hanuman::Graph.receive(stages: {
13
+ first_a: Hanuman::Stage.receive(label: :first_a), # ancestor
14
+ first_b: Hanuman::Stage.receive(label: :first_b), # ancestor,
15
+ second: Hanuman::Stage.receive(label: :second), # ancestor, descendent
16
+ third_a: Hanuman::Stage.receive(label: :third_a), # ancestor, descendent
17
+ third_b: Hanuman::Stage.receive(label: :third_b), # descendent
18
+ fourth: Hanuman::Stage.receive(label: :fourth), # descendent
19
+ },
20
+ links: [
21
+ Hanuman::LinkFactory.connect(:simple, :first_a, :second),
22
+ Hanuman::LinkFactory.connect(:simple, :first_b, :second),
23
+ Hanuman::LinkFactory.connect(:simple, :second, :third_a),
24
+ Hanuman::LinkFactory.connect(:simple, :second, :third_b),
25
+ Hanuman::LinkFactory.connect(:simple, :third_a, :fourth),
26
+ ]
27
+ )
28
+ end
29
+
30
+ let(:empty_tree) do
31
+ Hanuman::Tree.receive({})
32
+ end
33
+
34
+ let(:single_stage_tree) do
35
+ Hanuman::Tree.receive({stages: { first: Hanuman::Stage.receive(label: :first)}})
36
+ end
37
+
38
+ let(:tree) do
39
+ Hanuman::Tree.receive(stages: {
40
+ # important to mix up the order here so we
41
+ # can ensure that tree-sorting is working.
42
+ first: Hanuman::Stage.receive(label: :first), # ancestor,
43
+ third_b: Hanuman::Stage.receive(label: :third_b), # descendent
44
+ second: Hanuman::Stage.receive(label: :second), # ancestor, descendent
45
+ fourth: Hanuman::Stage.receive(label: :fourth), # descendent
46
+ third_a: Hanuman::Stage.receive(label: :third_a), # ancestor, descendent
47
+ },
48
+ links: [
49
+ Hanuman::LinkFactory.connect(:simple, :first, :second),
50
+ Hanuman::LinkFactory.connect(:simple, :second, :third_a),
51
+ Hanuman::LinkFactory.connect(:simple, :second, :third_b),
52
+ Hanuman::LinkFactory.connect(:simple, :third_a, :fourth),
53
+ ]
54
+ )
55
+ end
56
+
57
+ end