Ejemplo n.º 1
0
    def test_read_csv_dir_not_string(self):

        fp = open("test_file.csv", mode="w", newline='')
        fp.close()

        cwd = os.getcwd()
        os.replace(os.path.realpath(fp.name),
                   cwd + '/' + "Sensor Data" + '/' + os.path.basename(fp.name))

        with self.assertRaises(Exception):
            readCsvData.process_csv_file(123, fp.name)

        os.remove("Sensor Data" + '/' + fp.name)
Ejemplo n.º 2
0
    def test_read_csv_not_csv(self):

        directory = "Sensor Data"

        fp = open("test_file.txt", mode="w", newline='')
        fp.close()

        cwd = os.getcwd()
        os.replace(os.path.realpath(fp.name),
                   cwd + '/' + directory + '/' + os.path.basename(fp.name))

        with self.assertRaises(Exception):
            readCsvData.process_csv_file(directory, fp.name)

        os.remove(directory + "/" + fp.name)
Ejemplo n.º 3
0
    def test_read_csv_no_file(self):

        directory = "Sensor Data"

        fp = open("test_file.csv", mode="w", newline='')

        csv_writer = csv.writer(fp, delimiter=',')

        csv_writer.writerow(
            ["sensor_id", "sensor_type", "sensor_value", "timestamp"])
        csv_writer.writerow([
            "Level_5_Acc", "Accelerometer", 0.21, "17/11/1999 13:15:23.000589"
        ])

        fp.close()
        cwd = os.getcwd()
        os.replace(os.path.realpath(fp.name),
                   cwd + '/' + directory + '/' + os.path.basename(fp.name))
        os.remove(directory + "/" + fp.name)

        with self.assertRaises(Exception):
            readCsvData.process_csv_file(directory, fp.name)
Ejemplo n.º 4
0
    def test_read_csv_valid1(self):

        directory = "Sensor Data"

        fp = open("test_file.csv", mode="w", newline='')

        csv_writer = csv.writer(fp, delimiter=',')

        csv_writer.writerow(
            ["sensor_id", "sensor_type", "sensor_value", "timestamp"])
        csv_writer.writerow([
            "Level_1_Acc", "Accelerometer", 0.5, "12/06/1998 13:15:23.001589"
        ])
        csv_writer.writerow([
            "Level_3_Str", "Strain Gauge", 0.243, "12/06/1998 16:25:29.538532"
        ])

        fp.close()

        cwd = os.getcwd()
        os.replace(os.path.realpath(fp.name),
                   cwd + '/' + directory + '/' + os.path.basename(fp.name))

        input_data = readCsvData.process_csv_file(directory, fp.name)

        self.assertEqual(len(input_data), 2)

        for x in input_data[0].keys():
            self.assertTrue(
                x in ["sensor_id", "sensor_type", "sensor_value", "timestamp"])

        for y in input_data[0].values():
            self.assertTrue(y in [
                "Level_1_Acc", "Accelerometer", "0.5",
                "12/06/1998 13:15:23.001589"
            ])

        for x in input_data[1].keys():
            self.assertTrue(
                x in ["sensor_id", "sensor_type", "sensor_value", "timestamp"])

        for y in input_data[1].values():
            self.assertTrue(y in [
                "Level_3_Str", "Strain Gauge", "0.243",
                "12/06/1998 16:25:29.538532"
            ])

        os.remove(directory + "/" + fp.name)
Ejemplo n.º 5
0
    def test_read_csv_empty_csv(self):

        directory = "Sensor Data"

        fp = open("test_file.csv", mode="w", newline='')
        fp.close()

        cwd = os.getcwd()
        os.replace(os.path.realpath(fp.name),
                   cwd + '/' + directory + '/' + os.path.basename(fp.name))

        input_data = readCsvData.process_csv_file(directory, fp.name)

        self.assertEqual(len(input_data), 0)

        os.remove(directory + "/" + fp.name)
Ejemplo n.º 6
0
    def test_read_csv_file_not_string(self):

        directory = "Sensor Data"

        with self.assertRaises(Exception):
            readCsvData.process_csv_file(directory, 12345)
Ejemplo n.º 7
0
    def test_read_csv_valid2(self):

        directory = "Sensor Data"

        fp = open("test_file.csv", mode="w", newline='')

        csv_writer = csv.writer(fp, delimiter=',')

        csv_writer.writerow(
            ["sensor_id", "sensor_type", "sensor_value", "timestamp"])
        csv_writer.writerow([
            "Level_5_Acc", "Accelerometer", "0.21",
            "17/11/1999 13:15:23.000589"
        ])
        csv_writer.writerow([
            "Level_1_Str", "Strain Gauge", "-0.187",
            "20/09/20018 18:25:28.238032"
        ])
        csv_writer.writerow([
            "Level_5_Wire", "Wire Vibration", "-0.45",
            "17/10/2009 12:25:11.038532"
        ])

        fp.close()

        cwd = os.getcwd()
        os.replace(os.path.realpath(fp.name),
                   cwd + '/' + directory + '/' + os.path.basename(fp.name))

        input_data = readCsvData.process_csv_file(directory, fp.name)

        self.assertEqual(len(input_data), 3)

        for x in input_data[0].keys():
            self.assertTrue(
                x in ["sensor_id", "sensor_type", "sensor_value", "timestamp"])

        for y in input_data[0].values():
            self.assertTrue(y in [
                "Level_5_Acc", "Accelerometer", "0.21",
                "17/11/1999 13:15:23.000589"
            ])

        for x in input_data[1].keys():
            self.assertTrue(
                x in ["sensor_id", "sensor_type", "sensor_value", "timestamp"])

        for y in input_data[1].values():
            self.assertTrue(y in [
                "Level_1_Str", "Strain Gauge", "-0.187",
                "20/09/20018 18:25:28.238032"
            ])

        for x in input_data[2].keys():
            self.assertTrue(
                x in ["sensor_id", "sensor_type", "sensor_value", "timestamp"])

        for y in input_data[2].values():
            self.assertTrue(y in [
                "Level_5_Wire", "Wire Vibration", "-0.45",
                "17/10/2009 12:25:11.038532"
            ])

        os.remove(directory + "/" + fp.name)