Exemple #1
0
    def test_empty_init(self):

        #init and validation
        writer = testTarget.FILE_WRITER("C:\\SampleFolder")

        #Object assertions
        with self.assertRaises(FileNotFoundError):
            testTarget.FILE_WRITER("broken path string")

        self.assertIsNotNone(writer)
        self.assertIsInstance(writer, testTarget.FILE_WRITER)

        #Attribute assertions
        self.assertIsNotNone(writer.outName)
        self.assertIsNotNone(writer.outPath)
        self.assertEqual(writer.outPath, 'C:\\SampleFolder\\')
        self.assertEquals(writer.outName, "combined_gradebook")
Exemple #2
0
    def test_getPath(self):
        writer = testTarget.FILE_WRITER("C:/")

        self.assertIsInstance(writer.get_path(), str)
        self.assertNotEqual(len(writer.get_path()), 0)

        with self.assertRaises(TypeError):
            writer.get_path("too many params")
Exemple #3
0
    def test_writeCSV(self):
        writer = testTarget.FILE_WRITER("C:/SampleFolder")

        sampleCSV = ["This", "is", "A", "CSV"]
        simpData = [[1, 2, 3, 4, 5], ["A", "B", "C", "D", "E"]]
        #namedData = {"Nums":[1,2,3,4,5], "Letters":["A","B","C","D","E"]}
        panData = pandas.DataFrame([[1, 2, 3, 4, 5], ["A", "B", "C", "D",
                                                      "E"]])

        #Test normal writes.
        # self.assertTrue(writer.write_csv(simpData))
        #self.assertTrue(writer.write_csv(namedData))
        self.assertTrue(writer.write_csv(panData))
Exemple #4
0
    def test_setPath(self):
        writer = testTarget.FILE_WRITER("C:/")
        originalPath = "C:/"

        #Check invalid paths are not set
        self.assertFalse(writer.set_path("testing lol"))
        self.assertFalse(writer.set_path("Thisisntapath"))
        self.assertFalse(writer.set_path("''''"))
        self.assertFalse(writer.set_path("\.\/s\s\ds"))
        self.assertFalse(writer.set_path("213123123213"))
        self.assertFalse(writer.set_path("C:/Idontexist"))
        self.assertFalse(writer.set_path("C:/%username%"))
        self.assertFalse(writer.set_path("~%"))
        self.assertFalse(writer.set_path("/%"))
        self.assertFalse(writer.set_path("--"))
        self.assertFalse(writer.set_path("echo testing"))
        self.assertFalse(writer.set_path("ls"))
        self.assertFalse(writer.set_path(""))
        self.assertFalse(writer.set_path("  "))
        self.assertFalse(writer.set_path("                           "))

        #Check valid paths are set
        self.assertTrue(writer.set_path("C:/"))
        self.assertTrue(writer.set_path("C:\\"))
        self.assertTrue(writer.set_path("C:/SampleFolder"))
        self.assertTrue(writer.set_path("C:\\SampleFolder"))
        self.assertTrue(writer.set_path("C:\\Users\\"))
        self.assertTrue(writer.set_path("C:\\Windows\\System32"))

        # Check wrong type
        with self.assertRaises(TypeError):
            writer.set_path(int(5))
            writer.set_path(dict({1: "string"}))
            writer.set_path(True)
            writer.set_path(pd.DataFrame())
            writer.set_path(pd.Series())
            writer.set_path()