Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test.lua - github.com/torch/gnuplot.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2d83ec3cbd30b1b7523c96b88dd17ecd3bd93a96 (plain)
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'

local tester = torch.Tester()
local tests = {}

-- Returns a random string of lowercase digits
local function randomFilenameStr()
   local t = {}
   for i = 1, 10 do
      table.insert(t, string.char(math.random(97, 122)))
   end
   return table.concat(t)
end

-- Make sure we can write to a new filename, but not to a nonexistent directory.
function tests.cannotWriteToNonExistentDir()
   -- Save locally, this should work
   local validFilename = 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
   local nonExistentDir = 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...
   local invalidFilename = paths.concat(nonExistentDir, validFilename)
   local function shouldCrash()
      gnuplot.pngfigure(invalidFilename)
   end
   tester:assertErrorPattern(shouldCrash, 'directory does not exist')
end

tester:add(tests)
return tester:run()