def test_issue_155(self): """ Langmuir.max_motive raises ValueError There's a case where the `Langmuir.max_motive` method will raise a `ValueError`. Specifically when `self.critical_point_current_density() == self.calc_saturation_point_current_density()`. This condition is tested to ensure the `ValueError` is not raised. See: https://github.com/jrsmith3/tec/issues/155 """ em_params = { 'barrier': 1.0, 'emissivity': 0.0, 'position': 0.0, 'richardson': 10.0, 'temp': 300.0, 'voltage': 0.0 } co_params = { 'barrier': 1.0, 'emissivity': 0.0, 'position': 1.0, 'richardson': 10.0, 'temp': 300.0, 'voltage': 0.0 } em = Metal.from_dict(em_params) co = Metal.from_dict(co_params) l = Langmuir(em, co) try: l.max_motive() except ValueError: self.fail("Issue #155 not resolved")
def test_issue_155(self): """ Langmuir.max_motive raises ValueError There's a case where the `Langmuir.max_motive` method will raise a `ValueError`. Specifically when `self.critical_point_current_density() == self.calc_saturation_point_current_density()`. This condition is tested to ensure the `ValueError` is not raised. See: https://github.com/jrsmith3/tec/issues/155 """ em_params = {'barrier': 1.0, 'emissivity': 0.0, 'position': 0.0, 'richardson': 10.0, 'temp': 300.0, 'voltage': 0.0} co_params = {'barrier': 1.0, 'emissivity': 0.0, 'position': 1.0, 'richardson': 10.0, 'temp': 300.0, 'voltage': 0.0} em = Metal.from_dict(em_params) co = Metal.from_dict(co_params) l = Langmuir(em, co) try: l.max_motive() except ValueError: self.fail("Issue #155 not resolved")
def test_from_dict_additional_arbitrary_keys(self): """ Metal.from_dict can be instantiated with additional arbitrary keys """ self.input_params["not_an_argument"] = "not_an_argument" try: el = Metal.from_dict(self.input_params) except TypeError: self.fail("Instantiation failed with additional arbitrary args")
def test_from_dict_emissivity_non_numeric(self): """ Metal.from_dict instantiation requires numeric `emissivity` value """ self.input_params["emissivity"] = "this string is non-numeric." try: El = Metal.from_dict(self.input_params) except TypeError: # Attempting to instantiate a `tec.electrode.Metal` with a non-numeric `emissivity` argument raised a TypeError which is exactly what we wanted to do. pass else: self.fail("Shouldn't be able to instantiate with non-numeric `emissivity` argument.")
def test_voltage_non_numeric(self): """ Metal instantiation requires numeric `voltage` value """ self.input_params["voltage"] = "this string is non-numeric." try: El = Metal(**self.input_params) except TypeError: # Attempting to instantiate a `tec.electrode.Metal` with a non-numeric `voltage` argument raised a TypeError which is exactly what we wanted to do. pass else: self.fail( "Shouldn't be able to instantiate with non-numeric `voltage` argument." )
def setUp(self): """ Create new Langmuir object for every test """ if em.position > co.position: raise ValueError("Initialization em.position > co.position.") self.t = Langmuir(em, co) self.em = em self.co = co # Create `Langmuir` objects for each regime: accelerating, # space charge limited, and retarding. saturation_point_voltage = self.t.saturation_point_voltage() critical_point_voltage = self.t.critical_point_voltage() # accelerating mode: accelerating_voltage = saturation_point_voltage - units.Quantity( 1., "V") co_accelerating = Metal(**co_params) co_accelerating.voltage = accelerating_voltage self.t_accel = Langmuir(em, co_accelerating) # space charge limited mode: scl_voltage = (saturation_point_voltage + critical_point_voltage) / 2 co_scl = Metal(**co_params) co_scl.voltage = scl_voltage self.t_scl = Langmuir(em, co_scl) # retarding mode: retarding_voltage = critical_point_voltage + units.Quantity(1., "V") co_retarding = Metal(**co_params) co_retarding.voltage = retarding_voltage self.t_ret = Langmuir(em, co_retarding)
def setUp(self): """ Create new Langmuir object for every test """ if em.position > co.position: raise ValueError("Initialization em.position > co.position.") self.t = Langmuir(em, co) self.em = em self.co = co # Create `Langmuir` objects for each regime: accelerating, # space charge limited, and retarding. saturation_point_voltage = self.t.saturation_point_voltage() critical_point_voltage = self.t.critical_point_voltage() # accelerating mode: accelerating_voltage = saturation_point_voltage - units.Quantity(1., "V") co_accelerating = Metal(**co_params) co_accelerating.voltage = accelerating_voltage self.t_accel = Langmuir(em, co_accelerating) # space charge limited mode: scl_voltage = (saturation_point_voltage + critical_point_voltage) / 2 co_scl = Metal(**co_params) co_scl.voltage = scl_voltage self.t_scl = Langmuir(em, co_scl) # retarding mode: retarding_voltage = critical_point_voltage + units.Quantity(1., "V") co_retarding = Metal(**co_params) co_retarding.voltage = retarding_voltage self.t_ret = Langmuir(em, co_retarding)
def setUp(self): """ Create dict attribute that can instantiate a `Metal` object """ self.input_params = copy.copy(input_params) self.el = Metal(**input_params)
# -*- coding: utf-8 -*- import collections import numpy as np from tec.electrode import Metal from tec import TECBase from astropy import units import unittest import copy em = Metal(temp=1000., barrier=2., richardson=10.) co = Metal(temp=300., barrier=1., richardson=10., position=10.) class Base(unittest.TestCase): """ Base class for tests This class is intended to be subclassed so that I don't have to rewrite the same `setUp` method for each class containing tests. """ def setUp(self): """ Create new TECBase object for every test """ if em.position > co.position: raise ValueError("Initialization em.position > co.position.") self.t = TECBase(em, co) self.em = em self.co = co
from tec.models import Langmuir em_params = { "temp": 1000., "barrier": 2., "richardson": 10., } co_params = { "temp": 300., "barrier": 1., "richardson": 10., "position": 10., } em = Metal(**em_params) co = Metal(**co_params) class Base(unittest.TestCase): """ Base class for tests This class is intended to be subclassed so that I don't have to rewrite the same `setUp` method for each class containing tests. """ def setUp(self): """ Create new Langmuir object for every test """ if em.position > co.position: raise ValueError("Initialization em.position > co.position.")