[8028176] | 1 | #!/usr/bin/env python3 |
---|
[25b14be] | 2 | # -*- coding: utf-8 -*- |
---|
| 3 | |
---|
| 4 | import os |
---|
| 5 | import sys |
---|
| 6 | import pytest |
---|
[76c37a9] | 7 | from mock import patch |
---|
[25b14be] | 8 | |
---|
[76c37a9] | 9 | from . import _config_test |
---|
| 10 | sys.path.append('../Python') |
---|
[25b14be] | 11 | |
---|
[76c37a9] | 12 | from Classes.UioFiles import UioFiles |
---|
[25b14be] | 13 | |
---|
| 14 | |
---|
[76c37a9] | 15 | class TestUioFiles(): |
---|
| 16 | """Test class to test the UIOFiles methods.""" |
---|
[25b14be] | 17 | |
---|
[76c37a9] | 18 | @classmethod |
---|
| 19 | def setup_class(self): |
---|
| 20 | """Setup status""" |
---|
| 21 | self.testpath = os.path.join(_config_test.PATH_TEST_DIR, 'Dir') |
---|
| 22 | # Initialise and collect filenames |
---|
| 23 | self.files = UioFiles(self.testpath, '*.grb') |
---|
[25b14be] | 24 | |
---|
[76c37a9] | 25 | def test_listFiles(self): |
---|
| 26 | """Test the listFiles method from class UIOFiles.""" |
---|
[25b14be] | 27 | # set comparison information |
---|
| 28 | self.expected = ['FCGG__SL.20160410.40429.16424.grb', |
---|
[76c37a9] | 29 | 'FCOG__ML.20160410.40429.16424.grb', |
---|
| 30 | 'FCSH__ML.20160410.40429.16424.grb', |
---|
| 31 | 'OG_OROLSM__SL.20160410.40429.16424.grb', |
---|
| 32 | 'FCOG_acc_SL.20160409.40429.16424.grb', |
---|
| 33 | 'FCOG__SL.20160410.40429.16424.grb', |
---|
| 34 | 'FCSH__SL.20160410.40429.16424.grb'] |
---|
[25b14be] | 35 | |
---|
| 36 | # get the basename to just check for equality of filenames |
---|
[76c37a9] | 37 | filelist = [os.path.basename(f) for f in self.files.files] |
---|
[25b14be] | 38 | # comparison of expected filenames against the collected ones |
---|
| 39 | assert sorted(self.expected) == sorted(filelist) |
---|
| 40 | |
---|
| 41 | |
---|
[76c37a9] | 42 | def test_delete_files(self): |
---|
| 43 | """Test if a file is deleted.""" |
---|
| 44 | testfile = os.path.join(self.testpath, 'test.test') |
---|
| 45 | open(testfile, 'w').close() |
---|
| 46 | iofile = UioFiles(testfile, 'test.test') |
---|
| 47 | iofile.delete_files() |
---|
| 48 | assert [] == UioFiles(testfile, 'test.test').files |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | def test_str_(self): |
---|
| 52 | """Test if list of file is correctly converted to string.""" |
---|
[8028176] | 53 | self.expected = "FCOG__ML.20160410.40429.16424.grb, "\ |
---|
[76c37a9] | 54 | "FCOG__SL.20160410.40429.16424.grb, "\ |
---|
[8028176] | 55 | "FCSH__ML.20160410.40429.16424.grb, "\ |
---|
| 56 | "FCSH__SL.20160410.40429.16424.grb, "\ |
---|
[76c37a9] | 57 | "OG_OROLSM__SL.20160410.40429.16424.grb, "\ |
---|
| 58 | "FCGG__SL.20160410.40429.16424.grb, "\ |
---|
| 59 | "FCOG_acc_SL.20160409.40429.16424.grb" |
---|
| 60 | assert self.expected == self.files.__str__() |
---|