testkit123 0.2.4 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f614e8e95327241b534bbf266dad46525c6cd71adbedf8ca8044527cc9882a62
4
- data.tar.gz: 0777ac2e0d3c01b7d4a6238a428be34496f2cb3910f5bcb86075af1f37329325
3
+ metadata.gz: 560dc7d23a4b2dc3330982f8ca4ddbba94461f17ff22c4296d842eda8c92cd19
4
+ data.tar.gz: 3a5643258d69a643a57395f77d335acf78887187d70168e536c33d7141719955
5
5
  SHA512:
6
- metadata.gz: c36ff119e0864242544c179d34a2674524873b2458a65b43384018a46bff12ea9f9ed8579fa76b31a22e1723656a38d23ecea3bb001ccf160ec70b3191e1eb54
7
- data.tar.gz: 5596f0154676cb0893ad1db11bf20a35430ec566e5abd4f77f6208cce7af4f7d3ded1cff57848e55469a3d033669a2f1a2870a2124fda5b8e3277380328b20bc
6
+ metadata.gz: 6daac63a4f2e865788879f9541dde921f9dfd98580a48f0d725699ec535c43059087e1f9f6e36585d042bdee550e5a180f363a58a844c133ec62ebe95a315b3d
7
+ data.tar.gz: 219ebfe3cabc637e4db9966978843787f5d7cff22ece377052f4b64a5e3ca2a16e61f84d50a3bc80136ad9b14e31bd7651a6271a5e64aafd2ae312e982de691c
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/lib/testkit123.rb CHANGED
@@ -8,34 +8,89 @@ require 'testdata_text'
8
8
  require 'simple-config'
9
9
 
10
10
 
11
- class String
12
- def camelize
13
- self.split('_').collect(&:capitalize).join
11
+ module StringFormat
12
+
13
+ refine String do
14
+
15
+ def camelize
16
+ self.split('_').collect(&:capitalize).join
17
+ end
18
+
14
19
  end
20
+
15
21
  end
16
22
 
17
23
  class TestKit123
18
-
24
+ using StringFormat
25
+ using ColouredText
26
+
27
+ attr_reader :testdata_file
28
+
19
29
  def initialize(templates: {testdata: nil, testx: nil}, project: nil,
20
- debug: false, localpath: nil, datapath: nil,
30
+ debug: true, localpath: nil, datapath: nil,
21
31
  gemtest_url: nil, rubyver: 'ruby-2.5.1')
22
32
 
23
33
  @debug = debug
24
34
  @h = templates
25
35
 
36
+ #return unless project
37
+
38
+ @localpath, @datapath, @gemtest_url = localpath, datapath, gemtest_url
39
+ @rubyver = rubyver
40
+
41
+ return unless project
42
+
26
43
  @project_config = if project =~ /\.txt$/ then
27
44
  project
28
- elsif project
45
+ else
29
46
  File.join(localpath, project + '.txt')
30
47
  end
31
- puts '@project_config: ' + @project_config.inspect if @debug
32
48
 
33
-
34
- @localpath, @datapath, @gemtest_url = localpath, datapath, gemtest_url
35
- @rubyver = rubyver
49
+ puts '@project_config: ' + @project_config.inspect if @debug
50
+ puts 'localpath: ' + localpath.inspect if @debug
51
+
52
+ if File.exists? @project_config then
53
+
54
+ config = SimpleConfig.new(@project_config, debug: false).to_h
55
+ puts ('config: ' + config.inspect).debug if @debug
56
+
57
+ proj = config[:project]
58
+ puts 'create_standalone: proj: ' + proj.inspect if @debug
59
+
60
+ raise 'config[:data_path] not found' unless config[:data_path]
61
+
62
+ datafilepath = config[:data_path] + '/' + proj
63
+ test_rbfile = File.join(datafilepath, "test_#{proj}.rb")
64
+
65
+ ext = (config[:testdata_ext] and config[:testdata_ext][/\.?td$/]) ? 'td' : 'xml'
66
+ @testdata_file = File.join(datafilepath, "testdata_#{proj}.#{ext}")
67
+
68
+ end
36
69
 
37
70
  end
38
71
 
72
+ # expects a test node; see new_testnode()
73
+ #
74
+ def add_test(testnode)
75
+
76
+ s2 , filetype = RXFHelper.read @testdata_file
77
+ puts 'filetype: ' + filetype.inspect if @debug
78
+
79
+ xml = if s2.lstrip[0] == '<' then
80
+ s2
81
+ else
82
+ TestdataText.parse s2
83
+ end
84
+
85
+ puts 'xml: ' + xml.inspect if @debug
86
+
87
+ doc = Rexle.new(xml)
88
+ id = doc.root.xpath('records/test/summary/path/text()').last.to_i + 1
89
+ testnode.root.element('summary/path').text = id.to_s
90
+ doc.root.element('records').add testnode
91
+ return doc
92
+ end
93
+
39
94
  def create_files(project=@project_config)
40
95
 
41
96
  puts 'running create_files ...' if @debug
@@ -125,27 +180,34 @@ end
125
180
 
126
181
  # use the test number to find the test to copy from the test file
127
182
 
128
- config = SimpleConfig.new(@project_config).to_h
183
+ config = SimpleConfig.new(@project_config, debug: false).to_h
184
+ puts ('config: ' + config.inspect).debug if @debug
129
185
 
130
186
  proj = config[:project]
131
187
  puts 'create_standalone: proj: ' + proj.inspect if @debug
188
+
189
+ raise 'config[:data_path] not found' unless config[:data_path]
190
+
132
191
  datafilepath = config[:data_path] + '/' + proj
133
192
  test_rbfile = File.join(datafilepath, "test_#{proj}.rb")
134
193
 
135
- ext = config[:testdata_ext][/\.?td$/] ? 'td' : 'xml'
194
+ ext = (config[:testdata_ext] and config[:testdata_ext][/\.?td$/]) ? 'td' : 'xml'
136
195
  testdata_file = File.join(datafilepath, "testdata_#{proj}.#{ext}")
137
196
  puts 'testdata_file: ' + testdata_file.inspect if @debug
197
+ puts 'source code filepath: ' + test_rbfile.inspect if @debug
138
198
 
139
199
  s = File.read(test_rbfile).gsub(/^( )?end/,'')
140
200
  require_gems = s.scan(/^require +['"]([^'"]+)/).map(&:first)
141
201
 
142
- before_test = s[/(?<=def tests\(\)).*(?=\n test )/m].lstrip
143
-
202
+ before_test = s[/(?<=def tests\(\)).*/m].split(/ test /)[0].lstrip
203
+ puts '** before_test: ' + before_test.inspect
204
+
144
205
  a = s.split(/(?= test )/)
145
206
  a.shift
146
-
207
+ puts 'a: ' + a.inspect if @debug
208
+
147
209
  tests = a.map do |x|
148
- r = a[0].match(/(?<=['"])(?<test>[^"']+)['"]\s+do\s+\|(?<raw_args>[^\|]+)/)
210
+ r = x.match(/(?<=['"])(?<test>[^"']+)['"]\s+do\s+\|(?<raw_args>[^\|]+)/)
149
211
 
150
212
  [r[:test], r[:raw_args].split(/, */)]
151
213
  end
@@ -162,13 +224,39 @@ end
162
224
  puts 'xml: ' + xml.inspect if @debug
163
225
 
164
226
  doc = Rexle.new(xml)
165
- testnode = doc.root.xpath('records//test')[n-1]
227
+ puts 'after doc : ' if @debug
228
+ r = doc.root.xpath('records//test') || doc.root.xpath('records/test')
229
+
230
+ if @debug then
231
+ puts 'r: ' + r.inspect
232
+ puts 'r.length: ' + r.length.inspect
233
+ puts 'n: ' + n.inspect
234
+ end
235
+
236
+ testnode = r[n-1]
237
+ puts 'testnode: ' + testnode.xml.inspect if @debug
238
+
166
239
  title = testnode.text('summary/type')
240
+ puts ('title: ' + title.inspect).debug if @debug
241
+ puts ('tests: ' + tests.inspect).debug if @debug
167
242
  i = tests.index tests.assoc(title)
168
-
243
+ puts 'i: ' + i.inspect if @debug
244
+
169
245
  testcode = a[i].strip.lines[1..-2].map do |line|
170
246
  line.sub(/^ {6}/,'')
171
247
  end.join
248
+
249
+ # replace the input variable names with the input variable names defined
250
+ # in the testdata file and prefix them with *test_*.
251
+
252
+ input_vars = testnode.xpath('records/input/summary/*/name()')
253
+
254
+ puts 'input_vars: ' + input_vars.inspect
255
+ puts 'tests[i][1]: ' + tests[i][1].inspect
256
+ puts 'zip: ' + tests[i][1].zip(input_vars).inspect
257
+ tests[i][1].zip(input_vars).each do |x|
258
+ testcode.gsub!(/\b#{x[0]}\b/, 'test_' + x[1])
259
+ end
172
260
 
173
261
  args = testnode.xpath('records/input/summary/*').map do |input|
174
262
  "test_%s =<<EOF\n%s\nEOF\n" % [input.name,
@@ -185,12 +273,15 @@ end
185
273
 
186
274
  puts 'gems: ' + require_gems.inspect if @debug
187
275
 
276
+ codex = testcode.rstrip.lines
277
+
188
278
  "# Test %d. Type: %s\n# Description: %s\n" \
189
279
  % [n, title, testnode.text('summary/type')] + \
190
280
  "# --------------------------------------------\n\n" + \
191
281
  "require '#{proj}'\n" + require_gems.map {|x| "require '%s'" \
192
282
  % x}.join("\n") + "\n\n\n" \
193
- + before_test.gsub(/^ /,'') + "\n" + args.join("\n") + testcode
283
+ + before_test.gsub(/^ /,'') + "\n" + args.join("\n") \
284
+ + codex[0..-2].join + 'puts ' + codex.last
194
285
 
195
286
  end
196
287
 
@@ -221,16 +312,24 @@ end
221
312
 
222
313
  end
223
314
 
224
- def make_testdata(s)
315
+ def new_testnode(s=nil, type: '', inputs: {}, outputs: {result: ''})
225
316
 
226
- inputs = s.scan(/test_([\w]+) += +['"]([^'"]+)/)\
227
- .inject({}){|r,x| r.merge(x.first.to_sym => x.last)}
317
+ if s then
318
+
319
+ # the scan is intended to find the input variables from an
320
+ # example Ruby script
321
+
322
+ inputs = s.scan(/test_([\w]+) += +['"]([^'"]+)/)\
323
+ .inject({}){|r,x| r.merge(x.first.to_sym => x.last)}
324
+ end
325
+
326
+ # observe *test* is masked with *_test* because it is a built-in method name.
228
327
 
229
328
  h = {
230
329
  _test: {
231
330
  summary: {
232
331
  path: '',
233
- type: '',
332
+ type: type,
234
333
  description: ''
235
334
  },
236
335
  records: {
@@ -239,21 +338,22 @@ end
239
338
  records: {}
240
339
  },
241
340
  output: {
242
- summary: {result: ''},
341
+ summary: outputs,
243
342
  records: {}
244
343
  }
245
344
  }
246
345
  }
247
346
  }
248
347
 
249
- a = RexleBuilder.new(h).to_a
348
+ a = RexleBuilder.new(h, debug: false).to_a
250
349
 
251
- Rexle.new(a).xml pretty: true
350
+ Rexle.new(a)
252
351
 
253
352
  end
254
353
 
255
354
  def new_project(project='myproject', classname=nil, save: false)
256
355
 
356
+ puts 'inside new_project: ' + [project, classname].inspect if @debug
257
357
  classname ||= project.camelize
258
358
 
259
359
  s =<<EOF
@@ -276,8 +376,8 @@ test:
276
376
  end
277
377
  EOF
278
378
 
279
-
280
379
  if save then
380
+ puts '@localpath: ' + @localpath.inspect if @debug
281
381
  filepath = File.join(@localpath, project + '.txt')
282
382
  File.write filepath, s
283
383
  puts 'file saved ' + filepath if @debug
@@ -290,3 +390,4 @@ EOF
290
390
  end
291
391
 
292
392
  end
393
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testkit123
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -10,27 +10,32 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDXjCCAkagAwIBAgIBATANBgkqhkiG9w0BAQUFADAsMSowKAYDVQQDDCFnZW1t
14
- YXN0ZXIvREM9amFtZXNyb2JlcnRzb24vREM9ZXUwHhcNMTgwNzE1MTYwNTQ4WhcN
15
- MTkwNzE1MTYwNTQ4WjAsMSowKAYDVQQDDCFnZW1tYXN0ZXIvREM9amFtZXNyb2Jl
16
- cnRzb24vREM9ZXUwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCtgJ54
17
- gKuobwa5Won07os+Evt07yvbyEB7OBxwD3rnv1oNLxlx1wkOD2DNeZd4Otw1Dl6M
18
- plfQUJCzRU9sQ5cAKqHVDPpf+EJIPm2bATJlO8w//F/LULbN1h8VsbGBcXUu3VoX
19
- m2Bf6EesFKM/+BiMujEDX9EBy3hCJp7Bkn4WMk4PRwUdEBE8TEFj9T947+JVqZdR
20
- 3s4+DtYzFWbX9MuNzeQlAxcjV1iFgTS2G/GY6k6hJl0HhFnHfqftfqKgLIRZY4yF
21
- LIkb5Kvj/yA1gYctId0lk1PrntSchvQvzYDAOrf8lOY3M3JLkiOWzwcRWDoPWCaI
22
- PdYjRk0ij/x2zKS3AgMBAAGjgYowgYcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAw
23
- HQYDVR0OBBYEFJig7R4v8LRxNY/3qFTqBFgZT6FzMCYGA1UdEQQfMB2BG2dlbW1h
24
- c3RlckBqYW1lc3JvYmVydHNvbi5ldTAmBgNVHRIEHzAdgRtnZW1tYXN0ZXJAamFt
25
- ZXNyb2JlcnRzb24uZXUwDQYJKoZIhvcNAQEFBQADggEBAAaMtjTuuZeFtw4VuH9W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Mlf68ZTcrHiK8Loq4+LZoB+bAlZ+VQb5eYvR
24
+ UXfpjmEP30rnulkQFt9qwTtQUUY5/5/MeU29eoSgRg+dPKebapwxF80Fgb0CAwEA
25
+ AaOBijCBhzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUmNd64gCU
26
+ Me3RqaJGrXkwrpyEigswJgYDVR0RBB8wHYEbZ2VtbWFzdGVyQGphbWVzcm9iZXJ0
27
+ c29uLmV1MCYGA1UdEgQfMB2BG2dlbW1hc3RlckBqYW1lc3JvYmVydHNvbi5ldTAN
28
+ BgkqhkiG9w0BAQsFAAOCAYEA1RgOx9puiSkwKJn487dnDiuRSVsuBJFMZZhp+shk
29
+ ajXuyuC1TXrV97c14khNoUNofRhusOTgKkO6l/ouJsObSzUIFIQHt8ljFowM7rM6
30
+ ZOrFT08G0akM84d1dUCGCpTZyW7M0HmNxh4Yn2hIChejsfgwYZmesL7grqJ3WKvE
31
+ KZF9E6c0A0a60gAZWXb0Of0yXTSqiX2uNEkM7STyG+yu/XzLus+z2rEYdUFaxfvW
32
+ +AAeovOz8G+IQhuHZ6zG3KtRYeHq0057/tC44obGbyNOXC0twIUGJ0ajRedNKEc2
33
+ OC0wzHol3qEYmVai7DkQL8xX7m3VsWd/0JbS+tzchySc/e2R1I3FAGeOSzmUSN6o
34
+ 0CPM0BbOB4yUW+Ev7o3g31CsFuQ+5bCgR7n64QwTeHjlgFelmaJ1XalvnBC97S6k
35
+ /B2OocR7kLmSGm860fyULSY2RzLBKLOhjQHnrSiHj6n9pWrmkd+7Zxo/up/Jq4Xv
36
+ 0cPz7gMjFOVqEBQuSfoVKd9K
32
37
  -----END CERTIFICATE-----
33
- date: 2018-08-19 00:00:00.000000000 Z
38
+ date: 2021-02-01 00:00:00.000000000 Z
34
39
  dependencies:
35
40
  - !ruby/object:Gem::Dependency
36
41
  name: rxfhelper
@@ -38,40 +43,40 @@ dependencies:
38
43
  requirements:
39
44
  - - "~>"
40
45
  - !ruby/object:Gem::Version
41
- version: '0.8'
46
+ version: '1.0'
42
47
  - - ">="
43
48
  - !ruby/object:Gem::Version
44
- version: 0.8.5
49
+ version: 1.0.5
45
50
  type: :runtime
46
51
  prerelease: false
47
52
  version_requirements: !ruby/object:Gem::Requirement
48
53
  requirements:
49
54
  - - "~>"
50
55
  - !ruby/object:Gem::Version
51
- version: '0.8'
56
+ version: '1.0'
52
57
  - - ">="
53
58
  - !ruby/object:Gem::Version
54
- version: 0.8.5
59
+ version: 1.0.5
55
60
  - !ruby/object:Gem::Dependency
56
61
  name: simple-config
57
62
  requirement: !ruby/object:Gem::Requirement
58
63
  requirements:
59
64
  - - "~>"
60
65
  - !ruby/object:Gem::Version
61
- version: '0.6'
66
+ version: '0.7'
62
67
  - - ">="
63
68
  - !ruby/object:Gem::Version
64
- version: 0.6.4
69
+ version: 0.7.1
65
70
  type: :runtime
66
71
  prerelease: false
67
72
  version_requirements: !ruby/object:Gem::Requirement
68
73
  requirements:
69
74
  - - "~>"
70
75
  - !ruby/object:Gem::Version
71
- version: '0.6'
76
+ version: '0.7'
72
77
  - - ">="
73
78
  - !ruby/object:Gem::Version
74
- version: 0.6.4
79
+ version: 0.7.1
75
80
  - !ruby/object:Gem::Dependency
76
81
  name: testdata_text
77
82
  requirement: !ruby/object:Gem::Requirement
@@ -119,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
124
  version: '0'
120
125
  requirements: []
121
126
  rubyforge_project:
122
- rubygems_version: 2.7.6
127
+ rubygems_version: 2.7.10
123
128
  signing_key:
124
129
  specification_version: 4
125
130
  summary: Generates a test suite of files (for use with the testdata gem) from a config
metadata.gz.sig CHANGED
Binary file