Python Unit test

2016-01-26 Thread toluagboola
I'm a University student of IT with majors in Embedded Systems. I have this 
assignment where I have to write Unittest for a simple Python Code without 
having prior knowledge of Python. I really need some help.
Thanks
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Unit test

2016-01-26 Thread toluagboola
Yes I have studied the page but it's quite vague to me. So we have this project 
- Development of a touch screen controllable IEC61850 standard protocol 
analyzer. With this analyzer user can monitor and analyze network traffic in 
substation network.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Unit test

2016-01-26 Thread toluagboola
On Tuesday, January 26, 2016 at 10:57:51 PM UTC+2, 4ndre4 wrote:
> On 26/01/2016 11:09, toluagbo...@gmail.com wrote:
> 
> [...]
> > I'm a University student of IT with majors in Embedded Systems.
>  > I have this assignment where I have to write Unittest for a simple 
> Python Code
>  > without having prior knowledge of Python. I really need some help.
> 
> www.python.org to get a basic grasp on Python. There is a very good 
> tutorial there.
> 
> As for unit testing, you need to know a bit of the the theory behind it, 
> and how to use it in Python.
> 
> The following are four very good books about unit testing, in general:
> 
> Effective Unit Testing: A guide for Java developers - Lasse Koskela
> Test Driven: TDD and Acceptance TDD for Java Developers - Lasse Koskela
> Test-Driven Development: By Example - Kent Beck
> 
> This is a good book but with examples in C# (you might just get the 
> logic behind them):
> The Art of Unit Testing: with examples in C# - Roy Osherove
> 
> I am pretty sure that on Amazon you can find many others about specific 
> unit testing in Python.
> 
> On YouTube, there's a good number of videos about unit testing.
> This one, for example: https://www.youtube.com/watch?v=TWBDa5dqrl8
> 
> -- 
> 4ndre4
> "The use of COBOL cripples the mind; its teaching should, therefore, be 
> regarded as a criminal offense." (E. Dijkstra)

import getopt, sys
import dpkt, pcap

def usage():
print >>sys.stderr, 'usage: %s [-i device] [pattern]' % sys.argv[0]
sys.exit(1)

def main():
opts, args = getopt.getopt(sys.argv[1:], 'i:h')
name = None
for o, a in opts:
if o == '-i': name = a
else: usage()

pc = pcap.pcap(name)
pc.setfilter(' '.join(args))
decode = { pcap.DLT_LOOP:dpkt.loopback.Loopback,
   pcap.DLT_NULL:dpkt.loopback.Loopback,
   pcap.DLT_EN10MB:dpkt.ethernet.Ethernet }[pc.datalink()]
try:
print 'listening on %s: %s' % (pc.name, pc.filter)
for ts, pkt in pc:
print ts, `decode(pkt)`
except KeyboardInterrupt:
nrecv, ndrop, nifdrop = pc.stats()
print '\n%d packets received by filter' % nrecv
print '%d packets dropped by kernel' % ndrop

if __name__ == '__main__':
main()


Here is what the python code looks like and I am to make a Unittest for it
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python Unit test

2016-01-28 Thread toluagboola
Thanks for the contributions. Took a while but I got the function done. My 
problem was in the first two lines, I had to import the python file in my test 
code which I did not do earlier
-- 
https://mail.python.org/mailman/listinfo/python-list