Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathtest.lua
More file actions
Latest commit
52 lines (43 loc) · 1.53 KB
/
Copy pathtest.lua
File metadata and controls
52 lines (43 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require'gnuplot'
require'os'
require'paths'
require'torch'
localtester=torch.Tester()
localtests= {}
-- Returns a random string of lowercase digits
localfunctionrandomFilenameStr()
localt= {}
fori=1, 10do
table.insert(t, string.char(math.random(97, 122)))
end
returntable.concat(t)
end
-- Make sure we can write to a new filename, but not to a nonexistent directory.
functiontests.cannotWriteToNonExistentDir()
-- Save locally, this should work
localvalidFilename=randomFilenameStr() ..'.png'
-- If this already exists (bad luck!), don't let the test overwrite it
assert(not (paths.filep(validFilename) or
paths.dirp(validFilename)),
'random filename aready exists (?)')
-- Should work fine
gnuplot.pngfigure(validFilename)
gnuplot.plot({'Sin Curve',torch.sin(torch.linspace(-5,5))})
gnuplot.plotflush()
-- Clean up after ourselves
os.remove(validFilename)
-- Now make an invalid output
localnonExistentDir=randomFilenameStr()
assert(not (paths.filep(nonExistentDir) or
paths.dirp(nonExistentDir)),
'random dir aready exists (?)')
-- This makes an absolute path below cwd, seems Lua has no way (?) to query
-- the file separator charater by itself...
localinvalidFilename=paths.concat(nonExistentDir, validFilename)
localfunctionshouldCrash()
gnuplot.pngfigure(invalidFilename)
end
tester:assertErrorPattern(shouldCrash, 'directory does not exist')
end
tester:add(tests)
returntester:run()