iostreams 0.20.3 → 1.0.0.beta
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.
- checksums.yaml +4 -4
- data/lib/io_streams/bzip2/reader.rb +9 -21
- data/lib/io_streams/bzip2/writer.rb +9 -21
- data/lib/io_streams/deprecated.rb +217 -0
- data/lib/io_streams/encode/reader.rb +12 -16
- data/lib/io_streams/encode/writer.rb +9 -13
- data/lib/io_streams/errors.rb +6 -6
- data/lib/io_streams/gzip/reader.rb +7 -14
- data/lib/io_streams/gzip/writer.rb +7 -15
- data/lib/io_streams/io_streams.rb +182 -524
- data/lib/io_streams/line/reader.rb +9 -9
- data/lib/io_streams/line/writer.rb +10 -11
- data/lib/io_streams/path.rb +190 -0
- data/lib/io_streams/paths/file.rb +176 -0
- data/lib/io_streams/paths/http.rb +92 -0
- data/lib/io_streams/paths/matcher.rb +61 -0
- data/lib/io_streams/paths/s3.rb +269 -0
- data/lib/io_streams/paths/sftp.rb +99 -0
- data/lib/io_streams/pgp.rb +47 -19
- data/lib/io_streams/pgp/reader.rb +20 -28
- data/lib/io_streams/pgp/writer.rb +24 -46
- data/lib/io_streams/reader.rb +28 -0
- data/lib/io_streams/record/reader.rb +20 -16
- data/lib/io_streams/record/writer.rb +28 -28
- data/lib/io_streams/row/reader.rb +22 -26
- data/lib/io_streams/row/writer.rb +29 -28
- data/lib/io_streams/stream.rb +400 -0
- data/lib/io_streams/streams.rb +125 -0
- data/lib/io_streams/symmetric_encryption/reader.rb +5 -13
- data/lib/io_streams/symmetric_encryption/writer.rb +16 -15
- data/lib/io_streams/tabular/header.rb +9 -3
- data/lib/io_streams/tabular/parser/array.rb +8 -3
- data/lib/io_streams/tabular/parser/csv.rb +6 -2
- data/lib/io_streams/tabular/parser/hash.rb +4 -1
- data/lib/io_streams/tabular/parser/json.rb +3 -1
- data/lib/io_streams/tabular/parser/psv.rb +3 -1
- data/lib/io_streams/tabular/utility/csv_row.rb +9 -8
- data/lib/io_streams/utils.rb +22 -0
- data/lib/io_streams/version.rb +1 -1
- data/lib/io_streams/writer.rb +28 -0
- data/lib/io_streams/xlsx/reader.rb +7 -19
- data/lib/io_streams/zip/reader.rb +7 -26
- data/lib/io_streams/zip/writer.rb +21 -38
- data/lib/iostreams.rb +15 -15
- data/test/bzip2_reader_test.rb +3 -3
- data/test/bzip2_writer_test.rb +3 -3
- data/test/deprecated_test.rb +123 -0
- data/test/encode_reader_test.rb +3 -3
- data/test/encode_writer_test.rb +6 -6
- data/test/gzip_reader_test.rb +2 -2
- data/test/gzip_writer_test.rb +3 -3
- data/test/io_streams_test.rb +43 -136
- data/test/line_reader_test.rb +20 -20
- data/test/line_writer_test.rb +3 -3
- data/test/path_test.rb +30 -28
- data/test/paths/file_test.rb +206 -0
- data/test/paths/http_test.rb +34 -0
- data/test/paths/matcher_test.rb +111 -0
- data/test/paths/s3_test.rb +207 -0
- data/test/pgp_reader_test.rb +8 -8
- data/test/pgp_writer_test.rb +13 -13
- data/test/record_reader_test.rb +5 -5
- data/test/record_writer_test.rb +4 -4
- data/test/row_reader_test.rb +5 -5
- data/test/row_writer_test.rb +6 -6
- data/test/stream_test.rb +116 -0
- data/test/streams_test.rb +255 -0
- data/test/utils_test.rb +20 -0
- data/test/xlsx_reader_test.rb +3 -3
- data/test/zip_reader_test.rb +12 -12
- data/test/zip_writer_test.rb +5 -5
- metadata +33 -45
- data/lib/io_streams/base_path.rb +0 -72
- data/lib/io_streams/file/path.rb +0 -58
- data/lib/io_streams/file/reader.rb +0 -12
- data/lib/io_streams/file/writer.rb +0 -22
- data/lib/io_streams/http/reader.rb +0 -71
- data/lib/io_streams/s3.rb +0 -26
- data/lib/io_streams/s3/path.rb +0 -40
- data/lib/io_streams/s3/reader.rb +0 -28
- data/lib/io_streams/s3/writer.rb +0 -85
- data/lib/io_streams/sftp/reader.rb +0 -67
- data/lib/io_streams/sftp/writer.rb +0 -68
- data/test/base_path_test.rb +0 -35
- data/test/file_path_test.rb +0 -97
- data/test/file_reader_test.rb +0 -33
- data/test/file_writer_test.rb +0 -50
- data/test/http_reader_test.rb +0 -38
- data/test/s3_reader_test.rb +0 -41
- data/test/s3_writer_test.rb +0 -41
data/test/line_reader_test.rb
CHANGED
@@ -36,7 +36,7 @@ class LineReaderTest < Minitest::Test
|
|
36
36
|
|
37
37
|
it 'fails to keep embedded lines if flag is not set' do
|
38
38
|
lines = []
|
39
|
-
IOStreams::Line::Reader.
|
39
|
+
IOStreams::Line::Reader.file(csv_file) do |io|
|
40
40
|
io.each do |line|
|
41
41
|
lines << line
|
42
42
|
end
|
@@ -46,7 +46,7 @@ class LineReaderTest < Minitest::Test
|
|
46
46
|
|
47
47
|
it 'keeps embedded lines if flag is set' do
|
48
48
|
lines = []
|
49
|
-
IOStreams::Line::Reader.
|
49
|
+
IOStreams::Line::Reader.file(csv_file, embedded_within: '"') do |io|
|
50
50
|
io.each do |line|
|
51
51
|
lines << line
|
52
52
|
end
|
@@ -56,7 +56,7 @@ class LineReaderTest < Minitest::Test
|
|
56
56
|
|
57
57
|
it 'raises error for unclosed quote' do
|
58
58
|
assert_raises(RuntimeError) do
|
59
|
-
IOStreams::Line::Reader.
|
59
|
+
IOStreams::Line::Reader.file(unclosed_quote_file, embedded_within: '"') do |io|
|
60
60
|
io.each do |line|
|
61
61
|
end
|
62
62
|
end
|
@@ -68,7 +68,7 @@ class LineReaderTest < Minitest::Test
|
|
68
68
|
describe '#each' do
|
69
69
|
it 'each_line file' do
|
70
70
|
lines = []
|
71
|
-
count = IOStreams::Line::Reader.
|
71
|
+
count = IOStreams::Line::Reader.file(file_name) do |io|
|
72
72
|
io.each { |line| lines << line }
|
73
73
|
end
|
74
74
|
assert_equal data, lines
|
@@ -78,7 +78,7 @@ class LineReaderTest < Minitest::Test
|
|
78
78
|
it 'each_line stream' do
|
79
79
|
lines = []
|
80
80
|
count = File.open(file_name) do |file|
|
81
|
-
IOStreams::Line::Reader.
|
81
|
+
IOStreams::Line::Reader.stream(file) do |io|
|
82
82
|
io.each { |line| lines << line }
|
83
83
|
end
|
84
84
|
end
|
@@ -90,7 +90,7 @@ class LineReaderTest < Minitest::Test
|
|
90
90
|
it "autodetect delimiter: #{delimiter.inspect}" do
|
91
91
|
lines = []
|
92
92
|
stream = StringIO.new(data.join(delimiter))
|
93
|
-
count = IOStreams::Line::Reader.
|
93
|
+
count = IOStreams::Line::Reader.stream(stream, buffer_size: 15) do |io|
|
94
94
|
io.each { |line| lines << line }
|
95
95
|
end
|
96
96
|
assert_equal data, lines
|
@@ -100,7 +100,7 @@ class LineReaderTest < Minitest::Test
|
|
100
100
|
it "single read autodetect delimiter: #{delimiter.inspect}" do
|
101
101
|
lines = []
|
102
102
|
stream = StringIO.new(data.join(delimiter))
|
103
|
-
count = IOStreams::Line::Reader.
|
103
|
+
count = IOStreams::Line::Reader.stream(stream) do |io|
|
104
104
|
io.each { |line| lines << line }
|
105
105
|
end
|
106
106
|
assert_equal data, lines
|
@@ -112,7 +112,7 @@ class LineReaderTest < Minitest::Test
|
|
112
112
|
it "reads delimited #{delimiter.inspect}" do
|
113
113
|
lines = []
|
114
114
|
stream = StringIO.new(data.join(delimiter))
|
115
|
-
count = IOStreams::Line::Reader.
|
115
|
+
count = IOStreams::Line::Reader.stream(stream, buffer_size: 15, delimiter: delimiter) do |io|
|
116
116
|
io.each { |line| lines << line }
|
117
117
|
end
|
118
118
|
assert_equal data, lines
|
@@ -124,7 +124,7 @@ class LineReaderTest < Minitest::Test
|
|
124
124
|
delimiter = "\x01"
|
125
125
|
lines = []
|
126
126
|
stream = StringIO.new(data.join(delimiter).encode('ASCII-8BIT'))
|
127
|
-
count = IOStreams::Line::Reader.
|
127
|
+
count = IOStreams::Line::Reader.stream(stream, buffer_size: 15, delimiter: delimiter) do |io|
|
128
128
|
io.each { |line| lines << line }
|
129
129
|
end
|
130
130
|
assert_equal data, lines
|
@@ -141,7 +141,7 @@ class LineReaderTest < Minitest::Test
|
|
141
141
|
buffer_size = short_line.length + delimiter.size + (longer_line.size / 2)
|
142
142
|
|
143
143
|
stream = StringIO.new(data)
|
144
|
-
IOStreams::Line::Reader.
|
144
|
+
IOStreams::Line::Reader.stream(stream, buffer_size: buffer_size) do |io|
|
145
145
|
refute io.eof?
|
146
146
|
assert_equal delimiter, io.delimiter, -> { io.delimiter.ai }
|
147
147
|
|
@@ -158,7 +158,7 @@ class LineReaderTest < Minitest::Test
|
|
158
158
|
buffer_size = (longer_line.length + delimiter.size + 5) / 2
|
159
159
|
|
160
160
|
stream = StringIO.new(data)
|
161
|
-
IOStreams::Line::Reader.
|
161
|
+
IOStreams::Line::Reader.stream(stream, buffer_size: buffer_size) do |io|
|
162
162
|
refute io.eof?
|
163
163
|
assert_equal delimiter, io.delimiter, -> { io.delimiter.ai }
|
164
164
|
assert_equal longer_line, io.readline
|
@@ -174,7 +174,7 @@ class LineReaderTest < Minitest::Test
|
|
174
174
|
buffer_size = longer_line.length + 1
|
175
175
|
|
176
176
|
stream = StringIO.new(data)
|
177
|
-
IOStreams::Line::Reader.
|
177
|
+
IOStreams::Line::Reader.stream(stream, buffer_size: buffer_size) do |io|
|
178
178
|
refute io.eof?
|
179
179
|
assert_equal delimiter, io.delimiter, -> { io.delimiter.ai }
|
180
180
|
assert_equal longer_line, io.readline
|
@@ -191,7 +191,7 @@ class LineReaderTest < Minitest::Test
|
|
191
191
|
buffer_size = longer_line.length + 1
|
192
192
|
|
193
193
|
stream = StringIO.new(data)
|
194
|
-
IOStreams::Line::Reader.
|
194
|
+
IOStreams::Line::Reader.stream(stream, buffer_size: buffer_size) do |io|
|
195
195
|
refute io.eof?
|
196
196
|
assert_equal "\n", io.delimiter, -> { io.delimiter.ai }
|
197
197
|
assert_equal data, io.readline
|
@@ -205,7 +205,7 @@ class LineReaderTest < Minitest::Test
|
|
205
205
|
buffer_size = short_line.length + 100
|
206
206
|
|
207
207
|
stream = StringIO.new(data)
|
208
|
-
IOStreams::Line::Reader.
|
208
|
+
IOStreams::Line::Reader.stream(stream, buffer_size: buffer_size) do |io|
|
209
209
|
refute io.eof?
|
210
210
|
assert_equal "\n", io.delimiter, -> { io.delimiter.ai }
|
211
211
|
assert_equal short_line, io.readline
|
@@ -220,7 +220,7 @@ class LineReaderTest < Minitest::Test
|
|
220
220
|
buffer_size = longer_line.length + 1
|
221
221
|
|
222
222
|
stream = StringIO.new(data)
|
223
|
-
IOStreams::Line::Reader.
|
223
|
+
IOStreams::Line::Reader.stream(stream, buffer_size: buffer_size, delimiter: delimiter) do |io|
|
224
224
|
refute io.eof?
|
225
225
|
assert_equal delimiter, io.delimiter, -> { io.delimiter.ai }
|
226
226
|
assert_equal longer_line, io.readline
|
@@ -236,7 +236,7 @@ class LineReaderTest < Minitest::Test
|
|
236
236
|
buffer_size = longer_line.length + 1
|
237
237
|
|
238
238
|
stream = StringIO.new(data)
|
239
|
-
IOStreams::Line::Reader.
|
239
|
+
IOStreams::Line::Reader.stream(stream, buffer_size: buffer_size) do |io|
|
240
240
|
refute io.eof?
|
241
241
|
assert_equal delimiter, io.delimiter, -> { io.delimiter.ai }
|
242
242
|
assert_equal longer_line, io.readline
|
@@ -254,7 +254,7 @@ class LineReaderTest < Minitest::Test
|
|
254
254
|
data = [longer_line, short_line, longer_line].join(delimiter) + delimiter
|
255
255
|
|
256
256
|
stream = StringIO.new(data)
|
257
|
-
IOStreams::Line::Reader.
|
257
|
+
IOStreams::Line::Reader.stream(stream, buffer_size: buffer_size) do |io|
|
258
258
|
refute io.eof?
|
259
259
|
assert_equal delimiter, io.delimiter, -> { io.delimiter.ai }
|
260
260
|
assert_equal longer_line, io.readline
|
@@ -269,7 +269,7 @@ class LineReaderTest < Minitest::Test
|
|
269
269
|
data = [longer_line, short_line, longer_line].join(delimiter)
|
270
270
|
|
271
271
|
stream = StringIO.new(data)
|
272
|
-
IOStreams::Line::Reader.
|
272
|
+
IOStreams::Line::Reader.stream(stream, buffer_size: buffer_size) do |io|
|
273
273
|
refute io.eof?
|
274
274
|
assert_equal delimiter, io.delimiter, -> { io.delimiter.ai }
|
275
275
|
assert_equal longer_line, io.readline
|
@@ -283,7 +283,7 @@ class LineReaderTest < Minitest::Test
|
|
283
283
|
|
284
284
|
it 'reads empty file' do
|
285
285
|
stream = StringIO.new
|
286
|
-
IOStreams::Line::Reader.
|
286
|
+
IOStreams::Line::Reader.stream(stream) do |io|
|
287
287
|
assert io.eof?
|
288
288
|
end
|
289
289
|
end
|
@@ -292,7 +292,7 @@ class LineReaderTest < Minitest::Test
|
|
292
292
|
data = 'a' * IOStreams::Line::Reader::MAX_BLOCKS_MULTIPLIER + 'a'
|
293
293
|
stream = StringIO.new(data)
|
294
294
|
assert_raises IOStreams::Errors::DelimiterNotFound do
|
295
|
-
IOStreams::Line::Reader.
|
295
|
+
IOStreams::Line::Reader.stream(stream, buffer_size: 1) do |io|
|
296
296
|
end
|
297
297
|
end
|
298
298
|
|
data/test/line_writer_test.rb
CHANGED
@@ -18,7 +18,7 @@ class DelimitedWriterTest < Minitest::Test
|
|
18
18
|
it 'file' do
|
19
19
|
temp_file = Tempfile.new('rocket_job')
|
20
20
|
file_name = temp_file.to_path
|
21
|
-
IOStreams::Line::Writer.
|
21
|
+
IOStreams::Line::Writer.file(file_name) do |io|
|
22
22
|
lines.each { |line| io << line }
|
23
23
|
end
|
24
24
|
result = File.read(file_name)
|
@@ -27,7 +27,7 @@ class DelimitedWriterTest < Minitest::Test
|
|
27
27
|
|
28
28
|
it 'stream' do
|
29
29
|
io_string = StringIO.new
|
30
|
-
IOStreams::Line::Writer.
|
30
|
+
IOStreams::Line::Writer.stream(io_string) do |io|
|
31
31
|
lines.each { |line| io << line }
|
32
32
|
end
|
33
33
|
assert_equal raw, io_string.string
|
@@ -38,7 +38,7 @@ class DelimitedWriterTest < Minitest::Test
|
|
38
38
|
it 'returns byte count' do
|
39
39
|
io_string = StringIO.new
|
40
40
|
count = 0
|
41
|
-
IOStreams::Line::Writer.
|
41
|
+
IOStreams::Line::Writer.stream(io_string) do |io|
|
42
42
|
lines.each { |line| count += io.write(line) }
|
43
43
|
end
|
44
44
|
assert_equal raw, io_string.string
|
data/test/path_test.rb
CHANGED
@@ -2,50 +2,52 @@ require_relative 'test_helper'
|
|
2
2
|
|
3
3
|
module IOStreams
|
4
4
|
class PathTest < Minitest::Test
|
5
|
-
describe IOStreams do
|
6
|
-
describe '.
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
describe IOStreams::Path do
|
6
|
+
describe '.join' do
|
7
|
+
let(:path) { IOStreams::Path.new('some_path') }
|
8
|
+
|
9
|
+
it 'returns self when no elements' do
|
10
|
+
assert_equal path.object_id, path.join.object_id
|
10
11
|
end
|
11
12
|
|
12
|
-
it '
|
13
|
-
|
14
|
-
assert_equal path, IOStreams.root(:downloads).to_s
|
13
|
+
it 'adds element to path' do
|
14
|
+
assert_equal ::File.join('some_path', 'test'), path.join('test').to_s
|
15
15
|
end
|
16
|
-
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
assert_equal IOStreams.root.to_s, IOStreams.join.to_s
|
17
|
+
it 'adds paths to root' do
|
18
|
+
assert_equal ::File.join('some_path', 'test', 'second', 'third'), path.join('test', 'second', 'third').to_s
|
21
19
|
end
|
22
20
|
|
23
|
-
it '
|
24
|
-
assert_equal ::File.join(
|
21
|
+
it 'returns path and filename' do
|
22
|
+
assert_equal ::File.join('some_path', 'file.xls'), path.join('file.xls').to_s
|
25
23
|
end
|
26
24
|
|
27
|
-
it 'adds
|
28
|
-
assert_equal ::File.join(
|
25
|
+
it 'adds elements to path' do
|
26
|
+
assert_equal ::File.join('some_path', 'test', 'second', 'third', 'file.xls'), path.join('test', 'second', 'third', 'file.xls').to_s
|
29
27
|
end
|
30
28
|
|
31
|
-
it '
|
32
|
-
|
33
|
-
assert_equal path, IOStreams.join('file.xls').to_s
|
29
|
+
it 'return path as sent in when full path' do
|
30
|
+
assert_equal ::File.join('some_path', 'test', 'second', 'third', 'file.xls'), path.join('some_path', 'test', 'second', 'third', 'file.xls').to_s
|
34
31
|
end
|
32
|
+
end
|
35
33
|
|
36
|
-
|
37
|
-
|
38
|
-
assert_equal
|
34
|
+
describe '#absolute?' do
|
35
|
+
it 'true on absolute' do
|
36
|
+
assert_equal true, IOStreams::Path.new('/a/b/c/d').absolute?
|
39
37
|
end
|
40
38
|
|
41
|
-
it '
|
42
|
-
|
43
|
-
|
39
|
+
it 'false when not absolute' do
|
40
|
+
assert_equal false, IOStreams::Path.new('a/b/c/d').absolute?
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#relatve?' do
|
45
|
+
it 'true on relative' do
|
46
|
+
assert_equal true, IOStreams::Path.new('a/b/c/d').relative?
|
44
47
|
end
|
45
48
|
|
46
|
-
it '
|
47
|
-
|
48
|
-
assert_equal path, IOStreams.join(path).to_s
|
49
|
+
it 'false on absolute' do
|
50
|
+
assert_equal false, IOStreams::Path.new('/a/b/c/d').relative?
|
49
51
|
end
|
50
52
|
end
|
51
53
|
end
|
@@ -0,0 +1,206 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
module Paths
|
4
|
+
class FileTest < Minitest::Test
|
5
|
+
describe IOStreams::Paths::File do
|
6
|
+
let(:root) { IOStreams::Paths::File.new("/tmp/iostreams").delete_all }
|
7
|
+
let(:directory) { root.join('/some_test_dir') }
|
8
|
+
let(:data) { "Hello World" }
|
9
|
+
let(:file_path) do
|
10
|
+
path = root.join('some_test_dir/test_file.txt')
|
11
|
+
path.writer { |io| io << data }
|
12
|
+
path
|
13
|
+
end
|
14
|
+
let(:file_path2) do
|
15
|
+
path = root.join('some_test_dir/test_file2.txt')
|
16
|
+
path.writer { |io| io << "Hello World2" }
|
17
|
+
path
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '.temp_file' do
|
21
|
+
it 'returns value from block' do
|
22
|
+
result = IOStreams::Paths::File.temp_file('base', '.ext') { |_path| 257 }
|
23
|
+
assert_equal 257, result
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'supplies new temp file_name' do
|
27
|
+
path1 = nil
|
28
|
+
path2 = nil
|
29
|
+
IOStreams::Paths::File.temp_file('base', '.ext') { |path| path1 = path }
|
30
|
+
IOStreams::Paths::File.temp_file('base', '.ext') { |path| path2 = path }
|
31
|
+
refute_equal path1.to_s, path2.to_s
|
32
|
+
assert path1.is_a?(IOStreams::Paths::File), path1
|
33
|
+
assert path2.is_a?(IOStreams::Paths::File), path2
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe '#each_child' do
|
38
|
+
it 'iterates an empty path' do
|
39
|
+
none = nil
|
40
|
+
directory.join('does_not_exist').mkdir.each_child { |path| none = path }
|
41
|
+
assert_nil none
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'iterates a non-existant path' do
|
45
|
+
none = nil
|
46
|
+
directory.join('does_not_exist').each_child { |path| none = path }
|
47
|
+
assert_nil none
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'find all files' do
|
51
|
+
expected = [file_path.to_s, file_path2.to_s]
|
52
|
+
actual = root.children("**/*").collect(&:to_s)
|
53
|
+
assert_equal expected.sort, actual.sort
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'find matches case-insensitive' do
|
57
|
+
expected = [file_path.to_s, file_path2.to_s]
|
58
|
+
actual = root.children("**/Test*.TXT").collect(&:to_s)
|
59
|
+
assert_equal expected, actual.sort
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'find matches case-sensitive' do
|
63
|
+
skip "TODO"
|
64
|
+
expected = [file_path.to_s, file_path2.to_s]
|
65
|
+
actual = root.children("**/Test*.TXT", case_sensitive: true).collect(&:to_s)
|
66
|
+
refute_equal expected, actual.sort
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#mkpath' do
|
71
|
+
it 'makes path skipping file_name' do
|
72
|
+
new_path = directory.join('test_mkpath.xls').mkpath
|
73
|
+
assert ::File.exist?(directory.to_s)
|
74
|
+
refute ::File.exist?(new_path.to_s)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe '#mkdir' do
|
79
|
+
it 'makes entire path that does not have a file name' do
|
80
|
+
new_path = directory.join('more_path').mkdir
|
81
|
+
assert ::File.exist?(directory.to_s)
|
82
|
+
assert ::File.exist?(new_path.to_s)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
describe '#exist?' do
|
87
|
+
it 'true on existing file or directory' do
|
88
|
+
assert ::File.exist?(file_path.to_s)
|
89
|
+
assert ::File.exist?(directory.to_s)
|
90
|
+
|
91
|
+
assert directory.exist?
|
92
|
+
assert file_path.exist?
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'false when not found' do
|
96
|
+
non_existant_directory = directory.join('oh_no')
|
97
|
+
refute ::File.exist?(non_existant_directory.to_s)
|
98
|
+
|
99
|
+
non_existant_file_path = directory.join("abc.txt")
|
100
|
+
refute ::File.exist?(non_existant_file_path.to_s)
|
101
|
+
|
102
|
+
refute non_existant_directory.exist?
|
103
|
+
refute non_existant_file_path.exist?
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe '#size' do
|
108
|
+
it 'of file' do
|
109
|
+
assert_equal data.size, file_path.size
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe '#realpath' do
|
114
|
+
it 'already a real path' do
|
115
|
+
path = ::File.expand_path(__dir__, '../files/test.csv')
|
116
|
+
assert_equal path, IOStreams::Paths::File.new(path).realpath.to_s
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'removes ..' do
|
120
|
+
path = ::File.join(__dir__, '../files/test.csv')
|
121
|
+
realpath = ::File.realpath(path)
|
122
|
+
assert_equal realpath, IOStreams::Paths::File.new(path).realpath.to_s
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe '#move_to' do
|
127
|
+
it 'move_to existing file' do
|
128
|
+
IOStreams.temp_file("iostreams_move_test", ".txt") do |temp_file|
|
129
|
+
temp_file.write("Hello World")
|
130
|
+
begin
|
131
|
+
target = temp_file.directory.join("move_test.txt")
|
132
|
+
response = temp_file.move_to(target)
|
133
|
+
assert_equal target, response
|
134
|
+
assert target.exist?
|
135
|
+
refute temp_file.exist?
|
136
|
+
assert_equal "Hello World", response.read
|
137
|
+
assert_equal target.to_s, response.to_s
|
138
|
+
ensure
|
139
|
+
target&.delete
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'missing source file' do
|
145
|
+
IOStreams.temp_file("iostreams_move_test", ".txt") do |temp_file|
|
146
|
+
begin
|
147
|
+
refute temp_file.exist?
|
148
|
+
target = temp_file.directory.join("move_test.txt")
|
149
|
+
assert_raises Errno::ENOENT do
|
150
|
+
temp_file.move_to(target)
|
151
|
+
end
|
152
|
+
refute target.exist?
|
153
|
+
refute temp_file.exist?
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'missing target directories' do
|
159
|
+
IOStreams.temp_file("iostreams_move_test", ".txt") do |temp_file|
|
160
|
+
temp_file.write("Hello World")
|
161
|
+
begin
|
162
|
+
target = temp_file.directory.join("a/b/c/move_test.txt")
|
163
|
+
response = temp_file.move_to(target)
|
164
|
+
assert_equal target, response
|
165
|
+
assert target.exist?
|
166
|
+
refute temp_file.exist?
|
167
|
+
assert_equal "Hello World", response.read
|
168
|
+
assert_equal target.to_s, response.to_s
|
169
|
+
ensure
|
170
|
+
temp_file.directory.join("a").delete_all
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
describe '#delete' do
|
177
|
+
it 'deletes existing file' do
|
178
|
+
assert ::File.exist?(file_path.to_s)
|
179
|
+
file_path.delete
|
180
|
+
refute ::File.exist?(file_path.to_s)
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'ignores missing file' do
|
184
|
+
file_path.delete
|
185
|
+
file_path.delete
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe 'reader' do
|
190
|
+
it 'reads file' do
|
191
|
+
assert_equal data, file_path.reader(&:read)
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe 'writer' do
|
196
|
+
it 'creates file' do
|
197
|
+
new_file_path = directory.join("new.txt")
|
198
|
+
refute ::File.exist?(new_file_path.to_s)
|
199
|
+
new_file_path.writer { |io| io << data }
|
200
|
+
assert ::File.exist?(new_file_path.to_s)
|
201
|
+
assert_equal data.size, new_file_path.size
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|