def test_load_library(self): path = os.path.join(globProject.name, "mylib") os.makedirs(path) self.writeFile( path, "MyScript.py", """ @share def double(number): return number*2 @share def pow(number): return number*number def add(number): return number+1 """) session = Session.Session() env = {} session.init(scriptEnvironment=env) session.loadLibrary("MyScript", os.path.join(path, "MyScript.py")) self.assertEqual(env["MyScript"].double(5), 10) self.assertEqual(env["MyScript"].pow(4), 16) try: env["MyScript"].add(8) self.assertTrue(False) except: self.assertTrue(True)
def test_classes(self): project = self.createProject(Session.Session(), [self.createRequirement("framework")]) project.scan() requires = project.getRequires() self.assertEqual( requires[0].getScriptByName('framework.Base').getText(), ";")
def createCaseTwo(self): # application path = os.path.join(tempfile.TemporaryDirectory().name, "myproject") os.makedirs(path) def createFolders(): os.makedirs(os.path.join(path, "source")) os.makedirs(os.path.join(os.path.join(path, "source"), "class")) os.makedirs(os.path.join(os.path.join(path, "source"), "asset")) os.makedirs(os.path.join(os.path.join(path, "source"), "translation")) def createSampleScripts(): self.writeFile(os.path.join(path, "source"), "index.html", """<html></html>""") self.writeFile(os.path.join(os.path.join(path, "source"), "class"), "Main.js", ";") def createSampleAssets(): self.writeFile(os.path.join(os.path.join(path, "source"), "asset"), "main.css", """html{}""") def createSampleTranslations(): self.writeFile(os.path.join(os.path.join(path, "source"), "translation"), "de.po", " ") createFolders() self.createjpyaml(path) createSampleScripts() createSampleAssets() createSampleTranslations() return Project.getProjectFromPath(path, Session.Session())
def test_has_requires(self): project = self.createProject(Session.Session(), [ self.createRequirement("engine"), self.createRequirement("engine2") ]) project.scan() self.assertEqual(project.hasRequires(), True)
def test_set_field(self): session = Session.Session() session.addProject(self.createProject([])) session.setField("debug", True) self.assertEqual(session.exportFields(), '[[\'debug\', 2, true], [\'engine\', 2, "trident"]]')
def test_init(self): self.createProject([], onlyFileCreation=True) session = Session.Session() session.init() self.assertTrue(session.getProjectByName("myproject") is not None)
def test_subrequirement_classes(self): session = Session.Session() session.addProject( self.createProject(session, [ self.createRequirement( "engine", [self.createSubRequirement("framework")]) ])) self.assertEqual(len(session.getProjects()), 3)
def test_requires(self): project = self.createProject(Session.Session(), [ self.createRequirement("engine"), self.createRequirement("engine2") ]) project.scan() requires = project.getRequires() self.assertEqual(requires[0].getName(), "engine") self.assertEqual(requires[1].getName(), "engine2")
def test_subrequirement(self): project = self.createProject(Session.Session(), [ self.createRequirement("engine", [self.createSubRequirement("framework")]) ]) project.scan() requires = project.getRequires() self.assertEqual(requires[0].getName(), "engine") subrequires = requires[0].getRequires() self.assertEqual(subrequires[0].getName(), "framework")
def test_locale(self): session = Session.Session() session.addProject(self.createProject([])) session.setLocales(["de", "en_", "fr"]) counter = 0 for p in session.permutate(): counter += 1 self.assertEqual(counter, 24)
def test_pause_resume(self): session = Session.Session() session.addProject(self.createProject([])) try: session.pause() session.resume() self.assertTrue(True) except: self.assertTrue(False)
def test_other_process(self): project = self.createProject([]) try: session = Session.Session() session.addProject(project) session2 = Session.Session() session2.addProject(project) session2.pause() session.resume() self.assertTrue(True) except: self.assertTrue(False) try: session = Session.Session() session.addProject(project) session2 = Session.Session() session2.addProject(project) session2.resume() self.assertTrue(False) except: self.assertTrue(True) try: session = Session.Session() session.addProject(project) session2 = Session.Session() session2.addProject(project) session2.close() session2.clean() self.assertTrue(False) except: self.assertTrue(True) try: session = Session.Session() session.addProject(project) session2 = Session.Session() session2.addProject(project) session2.close() session.clean() self.assertTrue(False) except: self.assertTrue(True)
def test_same_subrequirements(self): frameworkPath = tempfile.TemporaryDirectory().name requirement1 = self.createRequirement( "engine", [self.createSubRequirement("framework", manPath=frameworkPath)]) requirement2 = self.createRequirement( "engine2", [self.createSubRequirement("framework", manPath=frameworkPath)]) session = Session.Session() session.addProject( self.createProject(session, [requirement1, requirement2])) self.assertEqual(len(session.getProjects()), 4)
def test_permutate(self): session = Session.Session() session.addProject(self.createProject([])) counter = 0 for p in session.permutate(): counter += 1 self.assertEqual(counter, 8) session.permutateField("engine", values=["webkit", "gecko", "trident"]) counter = 0 for p in session.permutate(): counter += 1 self.assertEqual(counter, 6) session.setField("debug", True) counter = 0 for p in session.permutate(): counter += 1 self.assertEqual(counter, 3)
def createCaseThree(self): # src path = os.path.join(tempfile.TemporaryDirectory().name, "myproject") os.makedirs(path) def createFolders(): os.makedirs(os.path.join(path, "src")) def createSampleScripts(): self.writeFile(os.path.join(path, "src"), "index.html", """<html></html>""") self.writeFile(os.path.join(path, "src"), "Main.js", ";") def createSampleAssets(): self.writeFile(os.path.join(path, "src"), "main.css", """html{}""") createFolders() self.createjpyaml(path) createSampleScripts() createSampleAssets() return Project.getProjectFromPath(path, Session.Session())
def test_set_permutation(self): session = Session.Session() session.addProject(self.createProject([])) session.permutateField("debug", values=[False, True], detect=None, default=True) session.permutateField("engine", values=["webkit", "gecko", "trident", "presto"], detect=None, default="gecko") self.assertEqual(session.exportFields(), '[[\'debug\', 2, true], [\'engine\', 2, "gecko"]]') session.permutateField("engine", values=["webkit"], detect=None, default="webkit") self.assertEqual(session.exportFields(), '[[\'debug\', 2, true], [\'engine\', 2, "webkit"]]')
# # Jasy - Web Tooling Framework # Copyright 2010-2012 Zynga Inc. # """This module is used to pass a single session instance around to different modules""" import jasy.core.Session as Session __all__ = ["session"] session = Session.Session() session.__doc__ = """Auto initialized session object based on jasy.core.Session"""