Exemplo n.º 1
0
 def __init__(self):
     """
     Contructor class Import Data class in charge to import sudokus
     data from different inputs such as csv or txt
     """
     self.csv_handler = CSVHandler()
     self.cmd_handler = CMDHandler()
Exemplo n.º 2
0
class TestCMDHandler(unittest.TestCase):

    def setUp(self):
        self.cmd_handler = CMDHandler()

    def test_sudoku_is_read_in_correct_format(self):
        input_line = "000000680000073009309000045490000000803050" + \
                      "902000000036960000308700680000028000000"
        exp_result = "000000680\n" + \
                     "000073009\n" + \
                     "309000045\n" + \
                     "490000000\n" + \
                     "803050902\n" + \
                     "000000036\n" + \
                     "960000308\n" + \
                     "700680000\n" + \
                     "028000000\n"
        sudoku = self.cmd_handler.get_rows_sudoku_data(input_line)
        self.assertEquals(exp_result, sudoku[0][0])

    def test_sudoku_is_read_correct_size(self):
        sudoku_size = 9
        input_line = "000000680000073009309000045490000000803050" + \
                      "902000000036960000308700680000028000000"
        exp_result = "000000680\n" + \
                     "000073009\n" + \
                     "309000045\n" + \
                     "490000000\n" + \
                     "803050902\n" + \
                     "000000036\n" + \
                     "960000308\n" + \
                     "700680000\n" + \
                     "028000000\n"
        sudoku = self.cmd_handler.get_rows_sudoku_data(input_line)
        self.assertEquals(sudoku_size, sudoku[0][1])

    def test_format_corect_when_invalid_sudoku_is_read(self):
        input_line = "000000680000073009309000045490000000803050902000000036"
        sudoku = self.cmd_handler.get_rows_sudoku_data(input_line)
        self.assertEquals(input_line, sudoku[0][0])

    def test_format_corect_when_invalid_sudoku_is_read(self):
        sudoku_size = -1
        input_line = "000000680000073009309000045490000000803050902000000036"
        sudoku = self.cmd_handler.get_rows_sudoku_data(input_line)
        self.assertEquals(sudoku_size, sudoku[0][1])
Exemplo n.º 3
0
class ImportData:
    extension_file_csv = ".csv"
    
    def __init__(self):
        """
        Contructor class Import Data class in charge to import sudokus
        data from different inputs such as csv or txt
        """
        self.csv_handler = CSVHandler()
        self.cmd_handler = CMDHandler()
    
    def read_sudoku_data_from_file(self, sudoku_file):
        """
        Read the sudoku data form files such as csv or txt
        Returns False if the data are invalid or the file was not
        able to read, return a matrix[][] wihich contains all the
        sudoku data and their sudoku size

        Keyword arguments:
        sudoku_file -- the path of the file which contains the
                       sudoku data

        """
        ext = self.get_extension_file(sudoku_file)
        matrix_sudoku = []
        if ext == self.extension_file_csv:
            matrix_sudoku = self.csv_handler.get_rows_sudoku_data(sudoku_file, ",")
        return matrix_sudoku

    def read_sudoku_data_from_line(self, line):
        """
        Read the sudoku data form a line entered form comand line
        Return a matrix[][] wihich contains the sudoku data and
        its sudoku size

        Keyword arguments:
        line -- the line string entered by the user

        """
        matrix_sudoku = self.cmd_handler.get_rows_sudoku_data(line)
        return matrix_sudoku
    
    def get_extension_file(self, filename):
        """
        Gess the extension of a given filename

        Keyword arguments:
        filename -- the filename to guess the extention

        """
        double_extensions = ['tar.gz', 'tar.bz2']
        root , ext = os.path.splitext(filename)
        if any([filename.endswith(x) for x in double_extensions]):
            root, first_ext = os.path.splitext(root)
            ext = first_ext + ext
        return ext
Exemplo n.º 4
0
 def setUp(self):
     self.cmd_handler = CMDHandler()