I've been looking around all week and can't wrap my head around how to get an instance of our pylons server started for use with the Behave BDD. Can any of you point me to an example or offer one of your own? Here's what I'm working with:
From the Tutorial page on the Behave doc site, starting a simple server and using selenium, this is their example code for Behave's features/environment.py:
import threading
from wsgiref import simple_server
from selenium import webdriver
from my_application import model
from my_application import web_app
def before_all(context):
context.server = simple_server.WSGIServer(('', 8000))
context.server.set_app(web_app.main(environment='test'))
context.thread = threading.Thread(target=context.server.serve_forever)
context.thread.start()
context.browser = webdriver.Chrome()
def after_all(context):
context.server.shutdown()
context.thread.join()
context.browser.quit()
def before_feature(context, feature):
model.init(environment='test')
It's a start, but I have no idea how to marry this to how our 'pylowiki' flavor of pylons is started up. There is another example I've found that may provide better clues, it is here. In this example I assume I'd replace "world" with "context", but aside from that the way the server is started in this example is different from how our own environment.py starts things up.
One last thing I think may be handy is to include the code from our current environment setup:
pylowiki/config/environment.py
# -*- coding: utf-8 -*-
"""Pylons environment configuration"""
import os
from mako.lookup import TemplateLookup
from pylons import config
from pylons.error import handle_mako_error
from sqlalchemy import engine_from_config
import pylowiki.lib.app_globals as app_globals
import pylowiki.lib.helpers
from pylowiki.config.routing import make_map
from pylowiki.model import init_model
def load_environment(global_conf, app_conf):
"""Configure the Pylons environment via the ``pylons.config``
object
"""
# Pylons paths
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
paths = dict(root=root,
controllers=os.path.join(root, 'controllers'),
static_files=os.path.join(root, 'public'),
templates=[os.path.join(root, 'templates')])
# Initialize config with the basic options
config.init_app(global_conf, app_conf, package='pylowiki', paths=paths)
config['routes.map'] = make_map()
config['pylons.app_globals'] = app_globals.Globals()
config['pylons.h'] = pylowiki.lib.helpers
# Create the Mako TemplateLookup, with the default auto-escaping
config['pylons.app_globals'].mako_lookup = TemplateLookup(
directories=paths['templates'],
error_handler=handle_mako_error,
module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
input_encoding='utf-8', output_encoding='utf-8', default_filters=['escape'],
imports=['from webhelpers.html import escape'])
# Setup the SQLAlchemy database engine
engine = engine_from_config(config, 'sqlalchemy.')
init_model(engine)
# CONFIGURATION OPTIONS HERE (note: all config options will override
# any Pylons config options)
behave documentation says you need environment.py in feature folder, at least, and steps folder accrdingly
https://behave.readthedocs.io/en/latest/gherkin.html#controlling-your-test-run-with-tags
Related
Whenever I need to use a file in Vscode whether if it is imported or in the CWD Vscode can not find it unless I enter the file path fully, is there anything that help to use files in current working directory. or when I import something like QIcon I have the same problem.
from PyQt6.QtWidgets import QApplication, QWidget
from PyQt6.QtGui import QIcon
import sys
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle('PyQT6 Window')
self.setWindowIcon("qt.png") # this is not working I need to set a path
def __init__(self, **kwargs):
self.__dict__.update(self._defaults) # set up default values
self.__dict__.update(kwargs) # and update with user overrides
self.class_names = self._get_class()
self.anchors = self._get_anchors()
self.sess = K.get_session()
RuntimeError: get_session is not available when using TensorFlow 2.0.
Tensorflow 2.0 does not expose the backend.get_session directly any more but the code still there and expose for tf1.
https://github.com/tensorflow/tensorflow/blob/r2.0/tensorflow/python/keras/backend.py#L465
You can use it with tf1 compatible interface:
sess = tf.compat.v1.keras.backend.get_session()
Or import tenforflow backend with internal path:
import tensorflow.python.keras.backend as K
sess = K.get_session()
In order to avoid using get_session after tensorflow 2.0 upgrade, Use tf.distribute.Strategy to get model. To load model, use tf.keras.models.load_model
import tensorflow as tf
another_strategy = tf.distribute.MirroredStrategy()
with another_strategy.scope():
model = Service.load_deep_model()
def load_deep_model(self, model):
loaded_model = tf.keras.models.load_model("model.h5")
return loaded_model
Hope this helps. As this worked for me.
I have tried to explain same at this utility article as well. https://www.javacodemonk.com/runtimeerror-get_session-is-not-available-when-using-tensorflow-2-0-f7238546
Probably has something to do with tf 2.0 eager execution that is enabled by default.
Try
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
I had the same error and tried installing and uninstalling. In the end, I found that the library was not actually installed correctly.
I went through each library in my:
C:\Users\MyName\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\
I tracked down the file in within the site-packages in Keras, which was calling from the Tensorflow library, which was calling from another folder. I found the final folder had the get_session(), but this was not being called in. When I checked the directory, I found that get_session wasn't being loaded in. Within the file directory /tensorflow/keras/backend.py it was importing everything, but missed out the get_session.
To fix this I added this line:
from tensorflow.python.keras.backend import get_session
Then saved it. The next time I ran my code it was fine.
I gave the same answer for this page How to fix ' module 'keras.backend.tensorflow_backend' has no attribute '_is_tf_1''
When trying to import JAVA modules I receive an error:
// JAVA imports
import lang::java::jdt::Java;
import lang::java::jdt::JDT;
import lang::java::jdt::JavaADT;
Could not load lang::java::jdt::Java
In the console:
rascal>import lang::java::jdt::Java;
|prompt:///|(0,29,<1,0>,<1,29>): Could not import module lang::java::jdt::Java: can not find in search path
Advice: |http://tutor.rascal-mpl.org/Errors/Static/ModuleImport/ModuleImport.html|
I'm using Eclipse and am trying to use the AstNode datatype. Any ideas?
The JDT modules have been replaced a while back by the m3 model.
While they are a bit different, the AST part should be comparable.
Check the m3 ast documentation and the Measuring java recipe.
Is this an old project you are trying to get up and running?
I have a dart web application using polymer. I can successfully run it with Dartium using boot.js. However, my index.html file is actually a Django template in another git repo for the project. Its uses template inheritance, among other things, so its not just a normal HTML file.
My goal is to have a Makefile compile the project on request. Currently, pub deploy will compile all the code, and it will run in non-dart browsers. However, my custom polymer elements do not end up being registered. They all show up as blank. Is this kind of setup even possible, that is, to not have an index.html entry point and build custom polymer elements? I could create a dummy buid.html to satisfy the entry-point requirement, but this seems like a sub-optimal solution.
My current buid.dart looks like:
import 'dart:io';
import 'package:polymer/component_build.dart';
import 'package:polymer/deploy.dart' as deploy;
main() {
build(new Options().arguments, [])
.then((_) => deploy.main());
}
and the output:
'package:polymer/component_build.dart': Error: line 68 pos 29: \
ambiguous reference: 'JSON' is defined in library 'dart:convert' \
and also in 'dart:io'
var message = JSON.encode([jsonMessage]);
The only way is to provide some HTML file as entry point. It doesn't matter when you use another HTML file in production if it contains the necessary script tags.
I'm following the example here: http://code.google.com/p/modwsgi/wiki/IntegrationWithPylons
however, it doesn't work - I get "ImportError: No module named paste.deploy" in the apache error log. Googling in this case helps not - I see some stuff about permissions, but all my permissions are fine. Where does paste.deploy really come from? It comes from PasteDeploy-1.3.4-py2.6.egg in site-packages, installed in my pylonsdevenv directory, right? Well, then how is apache supposed to know about that directory? Does the actual pylons project have to be in the pylonsdevenv directory?
thanks!
I added:
import site
site.addsitedir('/<yadayada>/pylonsdevenv/lib/python2.6/site-packages')
to the top of my wsgi file, and then set debug = False in my development.ini file (and later, deployment.ini file, I presume), that seemed to work...
If you can import (from paste.deploy import loadapp) manually it has to be a problem with sys.path. Also make sure that apache uses proper python interpreter. I have something like this in my "passanger_wsgi.py" on Dreamhost:
INTERP = "/home/myuser/bin/python"
if sys.executable != INTERP: os.execl(INTERP, INTERP, *sys.argv)
cwd = os.getcwd()
sys.path.append(os.getcwd())
sys.path.append('/home/myuser/blog')
You can try put some debug and check which paths are inside "sys.path".
Hope this helps.