Merge pull request #1155 from niphlod/tests/recfile

tests for modules NEED to be in a separate unittest
This commit is contained in:
mdipierro committed 2016-01-04 09:42:23 -06:00
commit cc40018e87
4 files changed
+42 -16

No files matched your search

+1 -15
View File
@@ -9,7 +9,7 @@
Generates names for cache and session files Generates names for cache and session files
-------------------------------------------- --------------------------------------------
""" """
import os, uuid import os
def generate(filename, depth=2, base=512): def generate(filename, depth=2, base=512):
@@ -63,17 +63,3 @@ def open(filename, mode="r", path=None):
if mode.startswith('w') and not os.path.exists(os.path.dirname(fullfilename)): if mode.startswith('w') and not os.path.exists(os.path.dirname(fullfilename)):
os.makedirs(os.path.dirname(fullfilename)) os.makedirs(os.path.dirname(fullfilename))
return file(fullfilename, mode) return file(fullfilename, mode)
def test():
if not os.path.exists('tests'):
os.mkdir('tests')
for k in range(20):
filename = os.path.join('tests', str(uuid.uuid4()) + '.test')
open(filename, "w").write('test')
assert open(filename, "r").read() == 'test'
if exists(filename):
remove(filename)
if __name__ == '__main__':
test()
+1
View File
@@ -10,6 +10,7 @@ from test_html import *
from test_is_url import * from test_is_url import *
from test_languages import * from test_languages import *
from test_router import * from test_router import *
from test_recfile import *
from test_routes import * from test_routes import *
from test_storage import * from test_storage import *
from test_serializers import * from test_serializers import *
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Unit tests for gluon.recfile
"""
import unittest
import os
import shutil
import uuid
from fix_path import fix_sys_path
fix_sys_path(__file__)
from gluon import recfile
class TestRecfile(unittest.TestCase):
def setUp(self):
os.mkdir('tests')
def tearDown(self):
shutil.rmtree('tests')
def testgeneration(self):
for k in range(20):
teststring = 'test%s' % k
filename = os.path.join('tests', str(uuid.uuid4()) + '.test')
with recfile.open(filename, "w") as g:
g.write(teststring)
self.assertEqual(recfile.open(filename, "r").read(), teststring)
is_there = recfile.exists(filename)
self.assertTrue(is_there)
recfile.remove(filename)
is_there = recfile.exists(filename)
self.assertFalse(is_there)
if __name__ == '__main__':
unittest.main()
-1
View File
@@ -1 +0,0 @@