top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

python - nose config

0 votes
23 views

I'm using nose to generate and run some tests not for python code, but for an html repository. I know this isn't the typical way to use nose, and so I'm asking here if the following code smells wrong.

I pass some args with the testconfig plugin and run a class setup method one time to get some information from a database. Then the tests get generated and run. During the run, a database is updated with the result. That is an intentional side-effect of running the test....is that okay or something that should never be done?

I've shortened the actual code to make it readable, but the main thing is the setup (setting class vars), the test generator, and the actual test (plus the database update):

class HtmlTester(object):
 '''
 Run this setup method once before tests begin.
 Reads from tconfig args to get document from database.
 '''
 @classmethod
 def setup_class(cls):
 name = tconfig['name']
 language = tconfig.get('language', 'en')
 report = db.conn({'name':name, 
 'language':language, 
 'format':'html})

 @attr('images')
 def test_images(self):
 for image in self.report['images']:
 yield (self.check_image, image)

 def check_image(self, image):
 '''
 True if image can be read, otherwise False
 '''
 r = False
 if get_imagesize(image):
 p = ImageFile.Parser()
 try:
 p.feed(open(image).read())
 except IOError:
 r = False
 else:
 r = True

 self.report.update({'image':image, 'result':r, 
 'name': self.name, 
 'language': self.language})
 assert_true(r)

 if __name__ == '__main__':
 args = sys.argv[:1] + ['--tc=name:mybook', 
 '--tc=language:en' ] + sys.argv[1:]
 nose.run(argv=args)

This is complex enough that I wonder if the above approach is correct.

posted Aug 15, 2013 by Deepak Dasgupta

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

Similar Questions
0 votes

i want to sent a response for my form submit from server to client, that means python flask to javascript. My javascript code is given follows

document.addEventListener('DOMContentLoaded', function() {

chrome.tabs.getSelected(null, function(tab) {
  d = document;
  var f = d.createElement('form');
  f.action = 'http://127.0.0.1:5000/Get%20Form/';
  f.method = 'post';
  var i = d.createElement('input');
  i.type = 'hidden';
  i.name = 'url';
  i.value = tab.url;
  f.appendChild(i);
  d.body.appendChild(f);
  f.submit();   
});
$(".button").click(function(){
    request = new XMLHttpRequest();
    request.open("POST","http://127.0.0.1:5000/PutValue/",true);
    request.send();
    request.addEventListener("readystatechange", processRequest,false);
    function processRequest(e)
    {
    if(request.readyState==4 && request.status == 200)
    {
    var response = JSON.parse(request.responseText);
    a=response.result
    alert(a);
    }
    }
});
},false);

And my Python server code is follows

from flask import Flask, flash, redirect, url_for, request, render_template,jsonify
import json
import UrlTest
import trainingSet as ts

app = Flask(__name__)
user=""
s=0

@app.route('/Get Form/',methods = ['POST'])
def GetForm():
request.method == 'POST'
url=request.form['url']
UrlTest.process_test_url(url,'test_features.csv')
s=ts.main_caller('url_features.csv','test_features.csv')
print s
return str(s)

@app.route('/PutValue/',methods = ['POST'])
def PutValue():
request.method == 'POST'
print s
return jsonify(result=s)


if (__name__ == '__main__'):
app.run(debug=True,host='0.0.0.0', use_reloader=False)

I want to send the value of s to the javascript client. please help me to send this the value of s.
and if u can suggest the complete code in javascipt and python

+1 vote

i want to create a chrome extension. its have complex mathematical queries. so i need to use python as scripting language. help me to implement python script in google chrome addon

+1 vote

I would like to create AWS monthly billing graph using python and python flask.so for this i need python script using that i have to get last 6 month's monthly bill in AWS.

For this, I have created one virtual environment in my local machine. for example my ip is: 127.0.0.0:5000. Here after pull that script, it's automatically connected to AWS and display's last 6 month's data. its my requirement.


Useful Links with Similar Problem
Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...