def test_Instrument_warnings(): Instr = Instrument() wedge = Wedge.Wedge(position=(0.5, 0, 0)) Instr.wedges = wedge with warnings.catch_warnings( record=True ) as w: # From https://docs.python.org/3.1/library/warnings.html # Cause all warnings to always be triggered. warnings.simplefilter("always") # Trigger a warning. Instr.wedges = wedge # Verify some things assert len(w) == 1 assert issubclass(w[0].category, UserWarning) assert 'The list of wedges is not empty! Appending new wedges(s)' in str( w[0].message)
def test_Instrument_error(): try: Instr = Instrument(fileName='wrongDummyFile.bin') assert False except ValueError: assert True Instr = Instrument() Ana = Analyser.FlatAnalyser(position=(0.5, 0, 0), direction=(1, 0, 1)) try: Instr.wedges = Ana assert False except AttributeError: assert True try: Instr.wedges = [Ana, Ana] assert False except AttributeError: assert True try: Instr.append("Wrong object type") assert False except AttributeError: assert True try: Instr.append(["List of", 3.0, "wrong objects"]) assert False except AttributeError: assert True try: Instr.settings = {'Name', 'New dictionary'} assert False except NotImplementedError: return True
def test_Instrument_init(): Instr = Instrument() assert (np.all(Instr.position == (0, 0, 0))) Det = Detector.Detector(position=(1.0, 1, 0), direction=(1, 0, 0)) Ana = Analyser.Analyser(position=(0.5, 0, 0), direction=(1, 0, 1)) wedge = Wedge.Wedge(detectors=[Det, Det], analysers=Ana) Instr.wedges = [wedge, wedge] assert (Instr.settings['Initialized'] == False)