Skip to content

Commit

Permalink
Ristrutturato tutto l'albero delle
Browse files Browse the repository at this point in the history
directory secondo http://jcalderone.livejournal.com/39794.html
in questa maniera si evita ogni tipo di incoerenza o ambiguità.
Aggiunto run_test.py per eseguire i test in maniera 'controllata'.
  • Loading branch information
silverfix committed Feb 17, 2011
1 parent dddb66d commit 5a2d546
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 61 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pyc
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from util import log_exc
from hwup_ircd.util import log_exc

#############################################
def handleException(e):
Expand Down
4 changes: 2 additions & 2 deletions irc_command.py → hwup_ircd/irc_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import string

import irc_regex
import irc_entity
from hwup_ircd import irc_regex
from hwup_ircd import irc_entity

# Le funzioni per gestire i comandi richiesti dal client

Expand Down
2 changes: 1 addition & 1 deletion irc_entity.py → hwup_ircd/irc_entity.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- coding: utf-8 -*-

from error import client_error
from hwup_ircd.error import client_error

#############################################
# Classe Channel: gestisce tutte le informazioni su un canale
Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions server.py → hwup_ircd/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import select
import socket

import irc_entity
import irc_command
from hwup_ircd import irc_entity
from hwup_ircd import irc_command

from util import log
from error import client_error
from error import generic_handler
from hwup_ircd.util import log
from hwup_ircd.error import client_error
from hwup_ircd.error import generic_handler


class Server(object):
Expand Down
9 changes: 9 additions & 0 deletions hwup_ircd/test/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-

"""
test
Questo è il package contenente tutti i test
"""
28 changes: 28 additions & 0 deletions hwup_ircd/test/mock_classes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-


#############################################
class Client(object): # classe mock che emula il comportamento/attributi della classe reale
def __init__(self):
self.password = None
self.nick = None
self.reply_output = None
self.ID = 0
self.sock = None
self.logged = False # Fin quando il client non invia la sequenza [pass->]nick->user
self.user = None
self.realName = None
self.flags = set() # Flag attivi per quell'utente
self.joinChannel_list = {}

def reply(self, reply_msg):
self.reply_output = reply_msg


#############################################
class Server(object): # classe mock che emula il comportamento/attributi della classe reale

def __init__(self,):
self.client_list = {}
self.socket_list = []
self.channel_list = {}
52 changes: 6 additions & 46 deletions test/basic.py → hwup_ircd/test/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,17 @@

import unittest

import sys
sys.path.append('../')
from hwup_ircd import irc_command
from hwup_ircd.test import mock_classes

import irc_command

#############################################
class Client(object): # classe mock che emula il comportamento/attributi della classe reale
def __init__(self):
self.password = None
self.nick = None
self.reply_output = None
self.ID = 0
self.sock = None
self.logged = False # Fin quando il client non invia la sequenza [pass->]nick->user
self.user = None
self.realName = None
self.flags = set() # Flag attivi per quell'utente
self.joinChannel_list = {}

def reply(self, reply_msg):
self.reply_output = reply_msg


#############################################
class Server(object): # classe mock che emula il comportamento/attributi della classe reale

def __init__(self,):
self.client_list = {}
self.socket_list = []
self.channel_list = {}


#############################################
class Test_irc_command(unittest.TestCase):
class Test_IRC_command(unittest.TestCase):

#############################################
def setUp(self): # viene chiamato prima di tutti (non di ognuno) i metodi di test
self.client = Client()
self.server = Server()
self.client = mock_classes.Client()
self.server = mock_classes.Server()

#############################################
def tearDown(self): # viene chiamato dopo ogni i metodi di test
Expand All @@ -62,16 +34,4 @@ def test_OK1(self): # test su una simulazione di traffico corretto client-server
irc_command.command_privmsg(self.client, dataSplit, self.server) # se privmsg da errore manderà una reply al client che andrà finire nell'attributo del mock: reply_output
if self.client.reply_output: # quindi se diverso da None il test avrà fallito
self.fail(self.client.reply_output)


#############################################
if __name__ == '__main__':
import platform

installed_ver = [int(i) for i in platform.python_version_tuple()] # verifica che la ver di python sia 3>= x >2.7
if installed_ver[0] == 3 or (installed_ver[0] == 2 and installed_ver[1] >= 7):
unittest.main()
else:
print('Needed Python version >=2.7')



1 change: 1 addition & 0 deletions hwup_ircd/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-# In python2 print è uno statement, utilizziamo la print di python3# che è una funzione per poter definire un endline diversofrom __future__ import print_functiondebug = Truedef log(msg, end='\n'): # a default stampa a fine stringa il newline print('-L- %s' % msg, end=end) def log_exc(msg, e, end='\n'): print('-E- %s %s' % (msg, e), end=end) if debug: import traceback traceback.print_exc()
Expand Down
11 changes: 6 additions & 5 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-

import sys
import util
from util import log
from util import log_exc
from server import Server

from hwup_ircd import util
from hwup_ircd.util import log
from hwup_ircd.util import log_exc
from hwup_ircd.server import Server

# Return codes:
ABEND = 1
Expand Down Expand Up @@ -41,5 +42,5 @@ def main():


#############################################
# Chiaramente da rimuovere
# Go!
if __name__ == '__main__': main()
15 changes: 15 additions & 0 deletions run_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-

import platform
import unittest

from hwup_ircd.test import test_basic


if __name__ == '__main__':
installed_ver = [int(i) for i in platform.python_version_tuple()] # verifica che la ver di python sia 3>= x >2.7
if installed_ver[0] == 3 or (installed_ver[0] == 2 and installed_ver[1] >= 7):
suite = unittest.TestLoader().loadTestsFromTestCase(test_basic.Test_IRC_command)
unittest.TextTestRunner(verbosity=2).run(suite)
else:
print('Needed Python version >=2.7')
1 change: 0 additions & 1 deletion util.py

This file was deleted.

0 comments on commit 5a2d546

Please sign in to comment.