Niepraktycznie i nieskładnie

o Test Driven Development




   Adam Przybyła <adam@ertel.com.pl>

       (Creative Commons cc-by-nd)

  Mikstura 2 Lateral Thinking - Rybnik 2013
Cykl życia
[root@synergia TDD_ANTLR]# cat test_mikstura.py
#! /usr/bin/python
import unittest

class test_moj(unittest.TestCase):
   def test_test(self):
       self.assertTrue(False)

if __name__ == '__main__':
    unittest.main()
[root@synergia TDD_ANTLR]#
[root@synergia TDD_ANTLR]# ./test_mikstura.py
F
==================================================
====================
FAIL: test_test (__main__.test_moj)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "./test_mikstura.py", line 6, in test_test
   self.assertTrue(False)
AssertionError

----------------------------------------------------------------------
Ran 1 test in 0.000s

FAILED (failures=1)
[root@synergia TDD_ANTLR]#
[root@synergia TDD_ANTLR]# cat test_mikstura.py
#! /usr/bin/python
import unittest

class test_moj(unittest.TestCase):
   def test_test(self):
       self.assertTrue(True)

if __name__ == '__main__':
    unittest.main()
[root@synergia TDD_ANTLR]#
[root@synergia TDD_ANTLR]# ./test_mikstura.py
.
----------------------------------------------------------------------
Ran 1 test in 0.000s

OK
[root@synergia TDD_ANTLR]#
#!/usr/bin/python
import unittest
import antlr3
from CSVLexer import CSVLexer
from CSVParser import CSVParser
class test_csv(unittest.TestCase):
     def setUp(self):
           pass

    def test_test(self):
         self.assertTrue(True)

    def test_lf(self):
         parser=parserek("n")
         wynik=parser.line()
         self.assertFalse(wynik)

    def test_crlf(self):
         parser=parserek("rn")
         wynik=parser.line()
         self.assertFalse(wynik)

    #@unittest.skip("omijam test")
    def test_red(self):
         parser=parserek("red")
         wynik=parser.pole()
         self.assertEqual(wynik,"red")
grammar CSV;
Options { language=Python; }
@header {
def test1(s): print "test"
}
line returns [wynik]
scope { wynik2 }
@init { wynik =[]; $line::wynik2=[]; }
: ( (NEWLINE) => NEWLINE
 | ( p1=pole {wynik.append(p1) } ( COMMA p1=pole {wynik.append(p1) } )* NEWLINE ) )
{ wynik=$line::wynik2};

COMMA : ( ' '* ',' ' '*) ;

pole returns [wynik1]
@init {
wynik1=""
try:
   wyn=$line::wynik2
except IndexError:
   wyn=[]
}
     : ( p=ZNAWIASEM { wynik1 = $p.text;}
     | p=BEZNAWIASU { wynik1 = $p.text;}
     | //nic
     ) {wyn.append(wynik1)};
NEWLINE : 'r'? 'n';

ZNAWIASEM : ('"' ( options {greedy=false;}: . )+ '"')+
   {txt = self.getText().strip('"').replace('""','"');self.setText(txt)};

BEZNAWIASU          : ~('r' | 'n' | ',' | ' ' | '"')+;
#! /usr/bin/python
# -*- coding: UTF-8 -*-
import unittest
from analizator import *
from pobieracz import *
from TDDczysciciel import Lexer
import pobieracz,analizator,warstwa_leksykalna,codecs,TDDczysciciel
class testy_pobierania(unittest.TestCase):
      def setUp(self):
           pass

    def test_dziala(self):
         self.assertTrue(True)

    def test_nazwy(self):
         self.assertTrue(nazwa_ma_ip("dns.ertel.com.pl"))

    def test_zlej_nazwy(self):
         self.assertFalse(nazwa_ma_ip("dns-45.ertel.com.pl"))

    def test_pinga_dziala(self):
         self.assertTrue(nazwa_odp_na_ping('127.0.0.1'))

    def test_pinga_niedziala(self):
         self.assertFalse(nazwa_odp_na_ping('224.0.0.0'))
Lateral Thinking


●   Wikinomia
●   Wikipedia
●   Wolna kultura
●   Falsyfikacja jako metoda naukowa i metoda testów
Pytania/pomysły?

Mikstura it2013

  • 1.
    Niepraktycznie i nieskładnie oTest Driven Development Adam Przybyła <adam@ertel.com.pl> (Creative Commons cc-by-nd) Mikstura 2 Lateral Thinking - Rybnik 2013
  • 2.
  • 3.
    [root@synergia TDD_ANTLR]# cattest_mikstura.py #! /usr/bin/python import unittest class test_moj(unittest.TestCase): def test_test(self): self.assertTrue(False) if __name__ == '__main__': unittest.main() [root@synergia TDD_ANTLR]#
  • 4.
    [root@synergia TDD_ANTLR]# ./test_mikstura.py F ================================================== ==================== FAIL:test_test (__main__.test_moj) ---------------------------------------------------------------------- Traceback (most recent call last): File "./test_mikstura.py", line 6, in test_test self.assertTrue(False) AssertionError ---------------------------------------------------------------------- Ran 1 test in 0.000s FAILED (failures=1) [root@synergia TDD_ANTLR]#
  • 5.
    [root@synergia TDD_ANTLR]# cattest_mikstura.py #! /usr/bin/python import unittest class test_moj(unittest.TestCase): def test_test(self): self.assertTrue(True) if __name__ == '__main__': unittest.main() [root@synergia TDD_ANTLR]#
  • 6.
  • 7.
    #!/usr/bin/python import unittest import antlr3 fromCSVLexer import CSVLexer from CSVParser import CSVParser class test_csv(unittest.TestCase): def setUp(self): pass def test_test(self): self.assertTrue(True) def test_lf(self): parser=parserek("n") wynik=parser.line() self.assertFalse(wynik) def test_crlf(self): parser=parserek("rn") wynik=parser.line() self.assertFalse(wynik) #@unittest.skip("omijam test") def test_red(self): parser=parserek("red") wynik=parser.pole() self.assertEqual(wynik,"red")
  • 8.
    grammar CSV; Options {language=Python; } @header { def test1(s): print "test" } line returns [wynik] scope { wynik2 } @init { wynik =[]; $line::wynik2=[]; } : ( (NEWLINE) => NEWLINE | ( p1=pole {wynik.append(p1) } ( COMMA p1=pole {wynik.append(p1) } )* NEWLINE ) ) { wynik=$line::wynik2}; COMMA : ( ' '* ',' ' '*) ; pole returns [wynik1] @init { wynik1="" try: wyn=$line::wynik2 except IndexError: wyn=[] } : ( p=ZNAWIASEM { wynik1 = $p.text;} | p=BEZNAWIASU { wynik1 = $p.text;} | //nic ) {wyn.append(wynik1)}; NEWLINE : 'r'? 'n'; ZNAWIASEM : ('"' ( options {greedy=false;}: . )+ '"')+ {txt = self.getText().strip('"').replace('""','"');self.setText(txt)}; BEZNAWIASU : ~('r' | 'n' | ',' | ' ' | '"')+;
  • 9.
    #! /usr/bin/python # -*-coding: UTF-8 -*- import unittest from analizator import * from pobieracz import * from TDDczysciciel import Lexer import pobieracz,analizator,warstwa_leksykalna,codecs,TDDczysciciel class testy_pobierania(unittest.TestCase): def setUp(self): pass def test_dziala(self): self.assertTrue(True) def test_nazwy(self): self.assertTrue(nazwa_ma_ip("dns.ertel.com.pl")) def test_zlej_nazwy(self): self.assertFalse(nazwa_ma_ip("dns-45.ertel.com.pl")) def test_pinga_dziala(self): self.assertTrue(nazwa_odp_na_ping('127.0.0.1')) def test_pinga_niedziala(self): self.assertFalse(nazwa_odp_na_ping('224.0.0.0'))
  • 10.
    Lateral Thinking ● Wikinomia ● Wikipedia ● Wolna kultura ● Falsyfikacja jako metoda naukowa i metoda testów
  • 11.