def setUp(self):
        # be executed before each test
        self.con = CmdController(CmdView(), ExcelView(), MatPlotView(),
                                 DBPickleView())

        self.con_view = CmdView()
        self.con_view.set_controller(self.con)
Exemplo n.º 2
0
class GraphingTests(unittest.TestCase):
    def setUp(self):
        # be executed before each test
        self.con = CmdController(CmdView(), ExcelView(), MatPlotView(),
                                 DBPickleView())

    def tearDown(self):
        # be executed after each test case
        print('End of Test\n\n')

    def test_PlotBaseData(self):
        self.con.matplot_data()

    def test_ImportDataThenPlot(self):
        self.con.import_from_excel("TestingDir\FullRangeValidTestFile.xls")
        self.con.validate_data()
        self.con.save_to_db()
        self.con.matplot_data()
Exemplo n.º 3
0
def main(script, *args):
    opt_args = GetOpt.get_opt(usage())

    mode = "gui"
    if opt_args.has_key("--cmd"):
        mode = "cmd"

    controller = None
    if "gui" == mode:
        controller = GuiController()
    else:
        controller = CmdController()
    controller.run()
Exemplo n.º 4
0
class GuiController(object):
    def __init__(self):
        self.cmd_controller = CmdController()

    #gui_controller的入口函数
    def run(self):
        #弹出nickname的对话框输入昵称
        gettext.install("nickname") # replace with the appropriate catalog name
        app = wx.PySimpleApp(0)
        wx.InitAllImageHandlers()
        nickname_dlg = NicknameDlg(None, wx.ID_ANY, "")
        app.SetTopWindow(nickname_dlg)
        nickname_dlg.Show()
        app.MainLoop()
        app.Destroy()

        if None == NicknameDlg.nickname or "" == NicknameDlg.nickname:
            return

        self.cmd_controller.set_nickname(NicknameDlg.nickname.encode('utf-8'))
        #启动游戏界面对话框
        app = GuiApp(self.cmd_controller, 0)
        app.MainLoop()
Exemplo n.º 5
0
class ExcelImportingTests(unittest.TestCase):
    def setUp(self):
        # be executed before each test
        self.con = CmdController(CmdView(), ExcelView(), MatPlotView(),
                                 DBPickleView())

    def tearDown(self):
        # be executed after each test case
        print('End of Test\n\n')

    def test_file_that_doesnt_exist(self):
        actual = self.con.import_from_excel(
            "TestingDir\AnotherDir\TestFile.xls")
        self.assertEqual(['That file or directory does not exist'], actual)

    def test_ImportAFile_ThatDoesntExist(self):
        expected = ['Invalid use of the command']
        actual = self.con.import_from_excel("TestFile")
        self.assertEqual(expected, actual)

    def test_import_a_valid_file(self):
        actual = self.con.import_from_excel("TestFile.xls")
        self.assertEqual(
            [['A123', 'M', 16.0, 123.0, 'Normal', 23.0, '20-10-2000'],
             ['A124', 'F', 16.0, 124.0, 'Normal', 24.0, '21-11-2000'],
             ['A125', 'M', 22.0, 129.0, 'Underweight', 29.0, '10-9-1994'],
             ['A126', 'M', 22.0, 129.0, 'Underweight', 29.0, '10-9-1994'],
             ['A127', 'M', 24.0, 127.0, 'Overweight', 27.0, '8-7-1992'],
             ['A128', 'F', 23.0, 128.0, 'Overweight', 28.0, '9-8-1993'],
             ['A129', 'M', 22.0, 129.0, 'Underweight', 29.0, '10-9-1994'],
             ['A130', 'F', 21.0, 130.0, 'Underweight', 30.0, '11-10-1995'],
             ['A131', 'M', 36.0, 131.0, 'Normal', 31.0, '3-4-1980'],
             ['A132', 'F', 31.0, 132.0, 'Overweight', 32.0, '8-7-1985']],
            actual)

    def test_importAndValidate_aTestFile_withAllValidData(self):
        self.con.import_from_excel("TestingDir\FullRangeValidTestFile.xls")
        actual = self.con.validate_data()
        self.assertEqual(actual, "Data is valid you can now save")
Exemplo n.º 6
0
 def __init__(self):
     self.cmd_controller = CmdController()
class DBSavingAndLoadingTests(unittest.TestCase):
    def setUp(self):
        # be executed before each test
        self.con = CmdController(CmdView(), ExcelView(), MatPlotView(),
                                 DBPickleView())

    def tearDown(self):
        # be executed after each test case
        print('End of Test\n\n')

    def test_loadFromDb_WithNoParameters(self):
        expected = [('T123', 'M', 20, 654, 'Normal', 56, '1996-10-18'),
                    ('G834', 'M', 54, 213, 'Overweight', 566, '1990-12-4'),
                    ('S931', 'F', 80, 986, 'Obesity', 852, '2001-5-1'),
                    ('P912', 'M', 34, 43, 'Underweight', 135, '1998-7-26'),
                    ('B720', 'F', 67, 867, 'Normal', 741, '1993-1-6')]
        actual = self.con.load_from_db('')
        self.assertEqual(expected, actual)

    def test_loadFromDb_WithAValidCondition(self):
        expected = [('G834', ), ('S931', ), ('P912', ), ('B720', )]
        actual = self.con.load_from_db('EMPID Age>20')
        self.assertEqual(expected, actual)

    def test_loadFromDb_withInvalidCommands(self):
        expected = 'Invalid use of the command'
        actual = self.con.load_from_db("This is broken")
        self.assertEqual(expected, actual)

    def test_SaveToDb_WithValidCommands(self):
        expected = 'Saved successfully'
        self.con.import_from_excel("TestingDir\FullRangeValidTestFile.xls")
        self.con.validate_data()
        actual = self.con.save_to_db()
        self.assertEqual(expected, actual)

    def test_SaveToDb_WithoutValidating(self):
        expected = "Please validate the data using the 'validate' command"
        self.con.import_from_excel("TestingDir\FullRangeValidTestFile.xls")
        actual = self.con.save_to_db()
        self.assertEqual(expected, actual)

    def test_SaveOneLineOfData_ToDb_WithValidCommands(self):
        expected = 'Saved successfully'
        self.con.import_from_excel("TestingDir\TestFileWithOneLineOfData.xls")
        self.con.validate_data()
        actual = self.con.save_to_db()
        self.assertEqual(expected, actual)
Exemplo n.º 8
0
class PickleSaveAndLoadTests(unittest.TestCase):
    def setUp(self):
        # be executed before each test
        self.con = CmdController(CmdView(), ExcelView(), MatPlotView(),
                                 DBPickleView())

    def tearDown(self):
        # be executed after each test case
        print('End of Test\n\n')

    def test_savingUsingPickle_invalidName(self):
        actual = self.con.db_pickle('s', '')
        self.assertEqual("Invalid use of the command", actual)

    def test_savingUsingPickle_shouldSaveAsTest(self):
        actual = self.con.db_pickle('s', 'test')
        self.assertEqual(["Saved Successfully as: test.pickle"], actual)

    def test_loadingWithPickle_withoutAFileName(self):
        actual = self.con.db_pickle('l', 'add')
        self.assertEqual("Invalid use of the command please enter "
                         "'replace'/'add' and a filename", actual)

    def test_loadingWithPickle_withoutValid_addOrReplaceParameter(self):
        actual = self.con.db_pickle('l', 'test')
        self.assertEqual("Invalid command please use either 'replace' or "
                         "'add'", actual)

    def test_loadingWithPickle_noParameters(self):
        actual = self.con.db_pickle('l', '')
        self.assertEqual("Invalid use of the command", actual)

    def test_loadingWithPickle_fileThatDoesntExist(self):
        actual = self.con.db_pickle('l', 'add TestFileThatDoesntExist')
        self.assertEqual(["File not found"], actual)

    def test_loadingWithPickle_importsAndReplaces(self):
        self.con.db_pickle('s', 'test')
        self.con.db_pickle('l', 'replace test')
        actual = self.con.load_from_db('')
        expected = [('T123', 'M', 20, 654, 'Normal', 56, '1996-10-18'),
                    ('G834', 'M', 54, 213, 'Overweight', 566, '1990-12-4'),
                    ('S931', 'F', 80, 986, 'Obesity', 852, '2001-5-1'),
                    ('P912', 'M', 34, 43, 'Underweight', 135, '1998-7-26'),
                    ('B720', 'F', 67, 867, 'Normal', 741, '1993-1-6')]
        self.assertEqual(expected, actual)

    def test_loadingWithPickle_importsAndAdds(self):
        self.con.db_pickle('s', 'test')
        self.con.db_pickle('l', 'add test')
        actual = self.con.load_from_db('')
        expected = [('T123', 'M', 20, 654, 'Normal', 56, '1996-10-18'),
                    ('G834', 'M', 54, 213, 'Overweight', 566, '1990-12-4'),
                    ('S931', 'F', 80, 986, 'Obesity', 852, '2001-5-1'),
                    ('P912', 'M', 34, 43, 'Underweight', 135, '1998-7-26'),
                    ('B720', 'F', 67, 867, 'Normal', 741, '1993-1-6')]
        self.assertEqual(expected, actual)
Exemplo n.º 9
0
from cmd_controller import CmdController
from cmd_view import CmdView
from db_pickle_view import DBPickleView
from excel_import_view import ExcelView
from matplot_view import MatPlotView

if __name__ == '__main__':
    controller = CmdController(CmdView(), ExcelView(), MatPlotView(),
                               DBPickleView())
    controller.go(controller)
Exemplo n.º 10
0
class ValidatingAndViewingTests(unittest.TestCase):
    def setUp(self):
        # be executed before each test
        self.con = CmdController(CmdView(), ExcelView(), MatPlotView(),
                                 DBPickleView())

    def tearDown(self):
        # be executed after each test case
        print('End of Test\n\n')

    def test_importAndValidate_aTestFile_withAllBadData(self):
        self.con.import_from_excel("TestingDir\FullRange"
                                   "InValidTestFile.xls")
        actual = self.con.validate_data()
        self.assertEqual(
            "Data not valid please correct it\n Invalid data on "
            "rows: 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 ", actual)

    def test_importAndValidateAndSave_aTestFile_withClashingPrimaryKeys(self):
        self.con.import_from_excel("TestingDir\TestFileWithClashingPrimaryKeys"
                                   ".xls")
        actual = self.con.validate_data()
        self.assertEqual(
            "Data not valid please correct it\n Invalid data on "
            "rows: 3 ", actual)

    def test_import_OthersTestData_withAllMixedData(self):
        self.con.import_from_excel("TestingDir\OthersTestingData.xls")
        actual = self.con.validate_data()
        self.assertEqual(
            "Data not valid please correct it\n Invalid data on "
            "rows: 2 3 8 9 10 13 14 15 16 17 18 19 21 22 23 24 "
            "25 26 27 28 29 30 33 34 35 36 37 38 39 40 41 42 45 "
            "50 51 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 "
            "68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 ", actual)

    def test_importAFile_thatIsInADirectory_and_viewTheData(self):
        self.con.import_from_excel("TestingDir\TestFile.xls")
        actual = self.con.view_currently_stored_import_data()
        self.assertEqual(
            [['A123', 'M', 16.0, 123.0, 'Normal', 23.0, '20-10-2000'],
             ['A124', 'F', 16.0, 124.0, 'Normal', 24.0, '21-11-2000'],
             ['A125', 'M', 22.0, 129.0, 'Underweight', 29.0, '10-9-1994'],
             ['A126', 'M', 22.0, 129.0, 'Underweight', 29.0, '10-9-1994'],
             ['A127', 'M', 24.0, 127.0, 'Overweight', 27.0, '8-7-1992'],
             ['A128', 'F', 23.0, 128.0, 'Overweight', 28.0, '9-8-1993'],
             ['A129', 'M', 22.0, 129.0, 'Underweight', 29.0, '10-9-1994'],
             ['A130', 'F', 21.0, 130.0, 'Underweight', 30.0, '11-10-1995'],
             ['A131', 'M', 36.0, 131.0, 'Normal', 31.0, '3-4-1980'],
             ['A132', 'F', 31.0, 132.0, 'Overweight', 32.0, '8-7-1985']],
            actual)

    def test_importAFile_and_viewTheData(self):
        self.con.import_from_excel("TestFile.xls")
        actual = self.con.view_currently_stored_import_data()
        self.assertEqual(
            [['A123', 'M', 16.0, 123.0, 'Normal', 23.0, '20-10-2000'],
             ['A124', 'F', 16.0, 124.0, 'Normal', 24.0, '21-11-2000'],
             ['A125', 'M', 22.0, 129.0, 'Underweight', 29.0, '10-9-1994'],
             ['A126', 'M', 22.0, 129.0, 'Underweight', 29.0, '10-9-1994'],
             ['A127', 'M', 24.0, 127.0, 'Overweight', 27.0, '8-7-1992'],
             ['A128', 'F', 23.0, 128.0, 'Overweight', 28.0, '9-8-1993'],
             ['A129', 'M', 22.0, 129.0, 'Underweight', 29.0, '10-9-1994'],
             ['A130', 'F', 21.0, 130.0, 'Underweight', 30.0, '11-10-1995'],
             ['A131', 'M', 36.0, 131.0, 'Normal', 31.0, '3-4-1980'],
             ['A132', 'F', 31.0, 132.0, 'Overweight', 32.0, '8-7-1985']],
            actual)