Browse Source

Fix creating test file for unit tests

zolfa-add_slices_loading
Ruben Verweij 8 years ago
parent
commit
e5557b0073
6 changed files with 22 additions and 2 deletions
  1. +2
    -0
      .gitignore
  2. +12
    -1
      nd2reader/common.py
  3. +2
    -1
      tests/test_common.py
  4. +2
    -0
      tests/test_legacy.py
  5. +2
    -0
      tests/test_parser.py
  6. +2
    -0
      tests/test_reader.py

+ 2
- 0
.gitignore View File

@ -52,3 +52,5 @@ coverage.xml
*.log *.log
*.pot *.pot
tests/test_data/

+ 12
- 1
nd2reader/common.py View File

@ -1,3 +1,4 @@
import os
import struct import struct
import array import array
from datetime import datetime from datetime import datetime
@ -329,6 +330,16 @@ def get_from_dict_if_exists(key, dictionary, convert_key_to_binary=True):
if convert_key_to_binary: if convert_key_to_binary:
key = six.b(key) key = six.b(key)
if not key in dictionary:
if key not in dictionary:
return None return None
return dictionary[key] return dictionary[key]
def check_or_make_dir(directory):
"""
Check if a directory exists, if not, create it
Args:
directory: the path to the directory
"""
if not os.path.exists(directory):
os.makedirs(directory)

+ 2
- 1
tests/test_common.py View File

@ -5,13 +5,14 @@ import struct
from nd2reader.artificial import ArtificialND2 from nd2reader.artificial import ArtificialND2
from nd2reader.common import get_version, parse_version, parse_date, _add_to_metadata, _parse_unsigned_char, \ from nd2reader.common import get_version, parse_version, parse_date, _add_to_metadata, _parse_unsigned_char, \
_parse_unsigned_int, _parse_unsigned_long, _parse_double
_parse_unsigned_int, _parse_unsigned_long, _parse_double, check_or_make_dir
from nd2reader.exceptions import InvalidVersionError from nd2reader.exceptions import InvalidVersionError
class TestCommon(unittest.TestCase): class TestCommon(unittest.TestCase):
def setUp(self): def setUp(self):
dir_path = path.dirname(path.realpath(__file__)) dir_path = path.dirname(path.realpath(__file__))
check_or_make_dir(path.join(dir_path, 'test_data/'))
self.test_file = path.join(dir_path, 'test_data/test.nd2') self.test_file = path.join(dir_path, 'test_data/test.nd2')
def create_test_nd2(self): def create_test_nd2(self):


+ 2
- 0
tests/test_legacy.py View File

@ -2,6 +2,7 @@ import unittest
from os import path from os import path
from nd2reader.artificial import ArtificialND2 from nd2reader.artificial import ArtificialND2
from nd2reader.common import check_or_make_dir
from nd2reader.legacy import Nd2 from nd2reader.legacy import Nd2
@ -12,6 +13,7 @@ class TestLegacy(unittest.TestCase):
def setUp(self): def setUp(self):
dir_path = path.dirname(path.realpath(__file__)) dir_path = path.dirname(path.realpath(__file__))
check_or_make_dir(path.join(dir_path, 'test_data/'))
self.test_file = path.join(dir_path, 'test_data/test.nd2') self.test_file = path.join(dir_path, 'test_data/test.nd2')
def test_can_open_test_file(self): def test_can_open_test_file(self):


+ 2
- 0
tests/test_parser.py View File

@ -1,6 +1,7 @@
import unittest import unittest
from os import path from os import path
from nd2reader.artificial import ArtificialND2 from nd2reader.artificial import ArtificialND2
from nd2reader.common import check_or_make_dir
from nd2reader.exceptions import InvalidVersionError from nd2reader.exceptions import InvalidVersionError
from nd2reader.parser import Parser from nd2reader.parser import Parser
@ -12,6 +13,7 @@ class TestParser(unittest.TestCase):
def setUp(self): def setUp(self):
dir_path = path.dirname(path.realpath(__file__)) dir_path = path.dirname(path.realpath(__file__))
check_or_make_dir(path.join(dir_path, 'test_data/'))
self.test_file = path.join(dir_path, 'test_data/test.nd2') self.test_file = path.join(dir_path, 'test_data/test.nd2')
self.create_test_nd2() self.create_test_nd2()


+ 2
- 0
tests/test_reader.py View File

@ -3,6 +3,7 @@ from os import path
import numpy as np import numpy as np
from nd2reader.artificial import ArtificialND2 from nd2reader.artificial import ArtificialND2
from nd2reader.common import check_or_make_dir
from nd2reader.parser import Parser from nd2reader.parser import Parser
from nd2reader.reader import ND2Reader from nd2reader.reader import ND2Reader
@ -14,6 +15,7 @@ class TestReader(unittest.TestCase):
def setUp(self): def setUp(self):
dir_path = path.dirname(path.realpath(__file__)) dir_path = path.dirname(path.realpath(__file__))
check_or_make_dir(path.join(dir_path, 'test_data/'))
self.test_file = path.join(dir_path, 'test_data/test.nd2') self.test_file = path.join(dir_path, 'test_data/test.nd2')
def test_can_open_test_file(self): def test_can_open_test_file(self):


Loading…
Cancel
Save