def test__config_format_3(self): """Tests hkshell start when the config file is in version 3.""" # Empty heap config_file = os.path.join(self._dir, 'test.cfg') config_str = \ ('[paths]\n' 'html_dir=my_html_dir\n' '\n' '[heaps/my_heap]\n' 'heap_id=my_heap\n' 'name=My heap\n' 'path=my_heap_dir\n') hkutils.string_to_file(config_str, config_file) cmdl_options, args = \ hkshell.parse_args(['--configfile', 'test.cfg', '--noshell', '--hkrc', 'NONE']) hkshell.main(cmdl_options, args) self.assertEqual( self.pop_log(), 'Warning: post directory does not exists: "my_heap_dir"\n' 'Post directory has been created.\n' 'Warning: HTML directory does not exists: "my_html_dir"\n' 'HTML directory has been created.')
def run_test(testname, testfun, prefix="", inline=True): # Executing the test logger.info("Running the %s test..." % testname) passed, res = testfun() # Examining the results if passed: logger.info("...the %s test passed" % testname) else: logger.info("...the %s test reported problems" % testname) caption = "%sproblems reported by the %s test" % (prefix, testname) if inline: sep = "#" * 79 prints("%s\n\n%s\n%s\n" % (caption, res.strip(), sep)) else: tmpprefix = testname + "_test_" filename = mkstemp(dir=tmp_dir, prefix=tmpprefix) hkutils.string_to_file(res, filename) msg = "The %s test reported problems: see the output in %s" % (testname, filename) prints("%s%s" % (prefix, msg)) return passed, res
def javascript_tester_old(): # This test will have problems when more than one wants to run at the same # time, because the second one will not be able to reserve port 8081. cfg_file = mkstemp(dir=tmp_dir, prefix="javascript.cfg.") js_tmp_dir = tempfile.mkdtemp(dir=tmp_dir, prefix="javascript.heap") s = "[heaps/myheap]\n" "path=%s\n" % js_tmp_dir hkutils.string_to_file(s, cfg_file) # We use port 8081 so that we don't disturb the service running on 8080 # (e.g a Heapkeeper web server). We sleep 5 seconds in the end to make sure # that the browser has the time to finish the request. call( [ "src/hk.py", "--configfile", cfg_file, "--hkrc", "NONE", "-c", "import hkweb", "-c", "hkweb.start(8081)", "-c", "import subprocess", "-c", ('subprocess.call(["google-chrome",' '"localhost:8081/static/html/test.html"])'), "-c", "import time", "-c", "time.sleep(5)", "--noshell", ] ) # We can't decide whether the tests passed or failed; the user has to do # that by looking at the opened browser. return (True, "")