Dec-26-2017, 04:49 PM
How can I write unit tests for this module. I know very little about writing tests.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
#-*-coding:utf8;-*- #qpy:3 #qpy:console SINGLETONS = [ 'area' , 'base' , 'br' , 'col' , 'command' , 'embed' , 'hr' , 'img' , 'input' , 'keygen' , 'link' , 'meta' , 'param' , 'source' , 'track' , 'wbr' ] def tagify(tagname, data = '', * * kw): attrs = '' retval = '' for key, value in zip (kw.keys(), kw.values()): if key = = 'cls' : key = 'class' if key = = '_id' : key = 'id' attrs + = '{}="{}"' . format (key, value) if not attrs: opentag = '<{}>' . format (tagname) else : opentag = '<{} {}>' . format (tagname, attrs) if not tagname in SINGLETONS: closetag = '</{}>' . format (tagname) else : closetag = None if not closetag: retval = '{}' . format (opentag) if data: retval = '{}{}{}' . format (opentag, data, closetag) else : retval = '{}{}' . format (opentag, closetag) return retval def tag(tagname, * * deco_kw): def deco(func): def wraps( * args, * * kw): data = func( * args, * * kw) return tagify(tagname, data, * * deco_kw) return wraps return deco |