Skip to content
Snippets Groups Projects
Commit 78d70d7c authored by Jan Caron's avatar Jan Caron
Browse files

scripts: Splitted the main in several smaller scripts

test: changed the dataloader TestCase
pyramex: first experiments with Cython and SCons
dataloader: changed the order in which the dimensions are saved,
        z_len is no longer part of the magnetization (this was the reason why
        we had to divide by res, which is equal to z_len for calculating coeff)
magcreator: shapes are now separate functions, mag_shape is now an argument for
        one unified create_hom_mag-function
phasemap: unification of the phasemap-functions in real space (just the pixel-
        field is calculated different now)
parent 0afb984a
No related branches found
No related tags found
No related merge requests found
# -*- coding: utf-8 -*-
"""
Unittests for pyramid.
"""
import unittest
import sys
from test_dataloader import *
from test_compliance import *
def run():
suite = unittest.TestSuite()
loader = unittest.TestLoader()
runner = unittest.TextTestRunner(verbosity=2)
suite.addTest(loader.loadTestsFromTestCase(TestCaseDataloader))
suite.addTest(loader.loadTestsFromTestCase(TestCaseCompliance))
runner.run(suite)
#TODO: why that?
# result = runner.run(suite)
# if result.wasSuccessful():
# sys.exit(0)
# else:
# sys.exit(1)
if __name__ == '__main__':
run()
#if __name__ == '__main__':
# suite = unittest.TestLoader().loadTestsFromTestCase(TestSuite)
# unittest.TextTestRunner(verbosity=2).run(suite)
''' GLORIPY VERSION '''
##! /usr/bin/python
#"""
#Unittests for pyjurassic.
#"""
#
#import unittest
#import os
#import sys
#import tests
#
#
#def main():
# all_tests = unittest.TestSuite()
# tl = unittest.defaultTestLoader
# if os.getenv("BOOST_TESTS_TO_RUN") is not None:
# return
# elif os.getenv("PYTHON_TESTS_TO_RUN") is None:
# all_tests.addTest(tl.loadTestsFromName("tests"))
# else:
# all_tests.addTest(tl.loadTestsFromName(os.getenv("PYTHON_TESTS_TO_RUN")))
#
# runner = unittest.TextTestRunner(verbosity=2)
# res = runner.run(all_tests)
# if res.wasSuccessful():
# sys.exit(0)
# else:
# sys.exit(1)
#
#
#if __name__ == '__main__':
# main()
\ No newline at end of file
import os
import unittest
class TestCompliance(unittest.TestCase):
"""
Class for checking compliance of pyjurassic.
"""
def setUp(self):
# self.getPaths()
# self.data_dir = "test_jrp_data"
# self.src_ctl = "ctl.py"
# remove E201 to get a working version of str(- b)
# remove E203 to get a working version of a[:, :]
# remove E501 as 80 chars are not enough
self.ignores = ["E201", "E203", "E501"]
self.options = ["dummy_name", "--ignore", ",".join(self.ignores), "--repeat"]
self.options += ["--exclude", "collections_python27.py"]
try:
import pep8
self.pep8 = pep8
except ImportError:
self.pep8 = None
print("\nWARNING: You do not have package pep8!")
def countErrors(self):
"""
Counts the relevant errors from the pep8 counter structure.
"""
return sum([self.pep8.options.counters[key]
for key in self.pep8.options.messages.keys()
if key not in self.ignores])
def checkDirectory(self, dir_name):
"""
Checks all python files in the supplied directory and subdirectories.
"""
self.pep8.process_options(self.options)
self.pep8.input_dir(dir_name)
return self.countErrors()
def test_pep8(self):
"""
Tests all directories containing python files for PEP8 compliance.
"""
self.assertTrue(self.pep8 is not None,
msg="Install Python pep8 module to fully execute testbench!")
errors = 0
for dir_name in ["test", os.environ["BUILDDIR"]]:
errors += self.checkDirectory(dir_name)
self.assertEqual(errors, 0)
# def test_variables(self):
# """
# Function for checking that all attributes are present.
# """
# try:
# import gloripy
## for name in ['X', 'Y', 'B',
## 'APR_VAL', 'APR_STD', 'FINAL_VAL', 'FINAL_STD',
## 'IG_VAL', 'TRUE_VAL',
## 'CARTESIAN', 'GEO', 'SPHERICAL',
## 'P', 'T', 'C']:
## self.assertTrue(hasattr(j, name), msg=str(name) + " is missing.")
# except ImportError:
# self.assertTrue(False, msg="could not import gloripy")
# def test_import(self):
# """
# Checks that all modules are importable.
# """
# module_list = ["gloripy",
# "gloripy.pylevel0",
# ]
# for module in module_list:
# try:
# exec("import " + module)
# importable = True
# except ImportError:
# importable = False
# self.assertTrue(importable, msg="importing " + module + " failed")
......@@ -7,23 +7,78 @@ Created on Wed Apr 24 07:10:28 2013
# py.test
import unittest
import numpy as np
import pyramid.dataloader as dl
from numpy import pi
class TestSuite(unittest.TestCase):
# TODO: define test constants somewhere
# TODO: proper error messages
# TODO: Docstring
class TestCaseDataloader(unittest.TestCase):
def setUp(self):
pass
self.filename = 'test_dataloader/test_data.txt'
self.mag_data = dl.MagDataLLG(self.filename)
def tearDown(self):
pass
self.filename = None
self.mag_data = None
def test_filename(self):
self.assertEqual(self.mag_data.filename, self.filename)
def test_resolution(self):
self.assertEqual(self.mag_data.res, 10.0)
def test_dimensions(self):
self.assertEqual(self.mag_data.dim, (1, 3, 5))
def test(self):
self.assertTrue(True)
def test_length(self):
self.assertEqual(self.mag_data.length, (10.0, 30.0, 50.0))
def test_almost(self):
self.assertAlmostEqual(0, 0.01, places=1)
def test_magnitude(self):
test_shape = (1, 3, 5)
test_array = np.zeros(test_shape)
z_mag = self.mag_data.magnitude[0]
y_mag = self.mag_data.magnitude[1]
x_mag = self.mag_data.magnitude[2]
self.assertEqual(z_mag.shape, test_shape)
self.assertEqual(y_mag.shape, test_shape)
self.assertEqual(x_mag.shape, test_shape)
np.testing.assert_array_equal(z_mag, test_array, 'Testmessage')
test_array[:,1,1:4] = np.cos(pi/4)
np.testing.assert_array_almost_equal(y_mag, test_array, err_msg='y failure')
np.testing.assert_array_almost_equal(x_mag, test_array, err_msg='x failure')
#mc.create_hom_mag((3,5),10.0,pi/4,mc.slab,((1,2),(1,3)),'test.txt',plot_mag_distr=True)
# '{:7.6e}'
# scale = 1.0E-9 / 1.0E-2 #from cm to nm
# data = np.genfromtxt(filename, skip_header=2)
# x_dim, y_dim, z_dim = np.genfromtxt(filename, dtype=int,
# skip_header=1,
# skip_footer=len(data[:, 0]))
# res = (data[1, 0] - data[0, 0]) / scale
# x_len, y_len, z_len = [data[-1, i]/scale+res/2 for i in range(3)]
# x_mag, y_mag, z_mag = [data[:, i].reshape(z_dim, y_dim, x_dim).mean(0)
# *z_len for i in range(3,6)]
# #Reshape in Python and Igor is different,
# #Python fills rows first, Igor columns!
# self.filename = filename
# self.res = res
# self.dim = (x_dim, y_dim, z_dim)
# self.length = (x_len, y_len, z_len)
# self.magnitude = (x_mag, y_mag, z_mag)
# self.assertAlmostEqual(0, 0.01, places=1)
# mc.create_hom_mag((10,10),10.0,0,mc.slab,((4,4),(5,5)),'test.txt')
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestSuite)
suite = unittest.TestLoader().loadTestsFromTestCase(TestCaseDataloader)
unittest.TextTestRunner(verbosity=2).run(suite)
\ No newline at end of file
LLGFileCreator2D: test_data
5 3 1
5.000000e-07 5.000000e-07 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 5.000000e-07 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 5.000000e-07 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 5.000000e-07 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 5.000000e-07 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 1.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 1.500000e-06 5.000000e-07 7.071068e-01 7.071068e-01 0.000000e+00
2.500000e-06 1.500000e-06 5.000000e-07 7.071068e-01 7.071068e-01 0.000000e+00
3.500000e-06 1.500000e-06 5.000000e-07 7.071068e-01 7.071068e-01 0.000000e+00
4.500000e-06 1.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
5.000000e-07 2.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
1.500000e-06 2.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
2.500000e-06 2.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
3.500000e-06 2.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
4.500000e-06 2.500000e-06 5.000000e-07 0.000000e+00 0.000000e+00 0.000000e+00
\ No newline at end of file
# -*- coding: utf-8 -*-
"""
Created on Wed Apr 24 07:10:28 2013
@author: Jan
"""
# py.test
import unittest
class TestSuite(unittest.TestCase):
def setUp(self):
pass
def tearDown(self):
pass
def test(self):
self.assertTrue(True)
def test_almost(self):
self.assertAlmostEqual(0, 0.01, places=1)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TestSuite)
unittest.TextTestRunner(verbosity=2).run(suite)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment