top button
Flag Notify
Site Registration

python - nose config

0 votes
161 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 LinkedIn Share Button

Similar Questions
–1 vote
  1. How to use listed below in command line (shell)?
    Change into a directory and list the contents
    Rename a file
    Create a new directory
    Create a new text file, and save it to a directory you just created
  2. How to use command-line Git or one of the many Git GUI clients like TortoiseGit, GitEye, Gitbox? Please list them.
  3. Please write a program, in any language, that counts down from 100 to 0 in steps of 2, and prints the numbers to the console or screen.
  4. Write a program, in python that iterates the numbers from 1 to 100.
    For any value divisible by 4, the program should print "Go".
    For any value divisible by 5, the program should print "Figure".
    For any value divisible by 4 and 5, the program should print "GoFigure".
0 votes
while len(word_letters) > 0 and lives > 0:
        # letters used
        # ' '.join(['a', 'b', 'cd']) --> 'a b cd'
        print('You have', lives, 'lives left and you have used these letters: ', ' '.join(used_letters))

        # what current word is (ie W - R D)
        word_list = [letters if letters in used_letters else '-' for letters in word]
        print(lives_visual_dict[lives])
        print('Current word: ', ' '.join(word_list))

https://www.youtube.com/watch?v=8ext9G7xspg
the part which i am finding difficult to understand appears at 32:15 of the above video.
i don't know how to highlight a part of a code while posting a question on this forum. this is my first post.
if someone can help than i would be very grateful.

0 votes

I'm working on association analysis on my dataset that consist majorly of categorical features and I'm using Cramers' V and Theils U statistical measures for showcasing the association metrics.

I have 2 questions related to the same :

If there are some missing values in some of the columns in my dataset, how should I handle them while calculation Cramers' V and theils u metrics? Shall I replace the missing value with some dummy value?
Note: I'm using python's python library for the calculation of both the metrics.

dython.nominal.cramers_v(data[field1],data[field2]) and dython.nominal.theils_u(data[field1],data[field2])

If I have a column name like "Task Creation Date" that consists of DateTime values. How can I include this field as part of my association analysis? Does Cramers' V and Theils U consider date values as input ? or some conversion is required?

Any help would be much appreciated.

...