Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

"""This module holds the automated tests for DGILib Auxiliary.""" 

 

from pydgilib.dgilib import DGILib 

from pydgilib.dgilib_config import ( 

CHANNEL_A, CHANNEL_B, POWER_CURRENT, POWER_VOLTAGE, POWER_RANGE, OLD_XAM, 

XAM, PAM, UNKNOWN, NUM_CALIBRATION, IDLE, RUNNING, DONE, CALIBRATING, 

INIT_FAILED, OVERFLOWED, USB_DISCONNECTED, CALIBRATION_FAILED, BUFFER_SIZE) 

 

import pytest 

from ctypes import c_uint 

 

verbosity = (0, 99) 

 

 

@pytest.mark.parametrize("verbose", verbosity) 

def test_auxiliary_power_initialize(verbose): 

"""test_auxiliary_power_initialize. 

 

DGILibAuxiliary.auxiliary_power_initialize 

""" 

with DGILib(verbose=verbose) as dgilib: 

assert isinstance(dgilib.auxiliary_power_initialize(), c_uint) 

 

 

@pytest.mark.parametrize("verbose", verbosity) 

def test_auxiliary_power_uninitialize(verbose): 

"""test_auxiliary_power_uninitialize. 

 

DGILibAuxiliary.auxiliary_power_uninitialize 

""" 

with DGILib(verbose=verbose) as dgilib: 

dgilib.power_hndl = dgilib.auxiliary_power_initialize() 

assert dgilib.auxiliary_power_uninitialize() is None 

 

 

@pytest.mark.parametrize("channel, power_type", [ 

(CHANNEL_A, POWER_CURRENT), (CHANNEL_B, POWER_CURRENT), 

(CHANNEL_A, POWER_VOLTAGE), (CHANNEL_B, POWER_VOLTAGE), 

(CHANNEL_A, POWER_RANGE), (CHANNEL_B, POWER_RANGE)]) 

@pytest.mark.parametrize("verbose", verbosity) 

def test_auxiliary_power_register_unregister_buffer_pointers( 

channel, power_type, verbose): 

"""test_auxiliary_power_register_unregister_buffer_pointers. 

 

DGILibAuxiliary.auxiliary_power_register_buffer_pointers 

DGILibAuxiliary.auxiliary_power_unregister_buffer_pointers 

""" 

with DGILib(verbose=verbose) as dgilib: 

dgilib.power_hndl = dgilib.auxiliary_power_initialize() 

dgilib.auxiliary_power_register_buffer_pointers( 

channel, power_type) 

dgilib.auxiliary_power_unregister_buffer_pointers( 

channel, power_type) 

dgilib.auxiliary_power_uninitialize() 

 

 

@pytest.mark.parametrize("verbose", verbosity) 

def test_auxiliary_power_calibration_is_valid(verbose): 

"""test_auxiliary_power_calibration_is_valid. 

 

DGILibAuxiliary.auxiliary_power_calibration_is_valid 

""" 

with DGILib(verbose=verbose) as dgilib: 

dgilib.power_hndl = dgilib.auxiliary_power_initialize() 

assert isinstance(dgilib.auxiliary_power_calibration_is_valid(), bool) 

dgilib.auxiliary_power_uninitialize() 

 

 

@pytest.mark.parametrize("verbose", verbosity) 

def test_auxiliary_power_get_circuit_type(verbose): 

"""test_auxiliary_power_get_circuit_type. 

 

DGILibAuxiliary.auxiliary_power_get_circuit_type 

""" 

with DGILib(verbose=verbose) as dgilib: 

dgilib.power_hndl = dgilib.auxiliary_power_initialize() 

assert dgilib.auxiliary_power_get_circuit_type() in (OLD_XAM, XAM, PAM, 

UNKNOWN) 

dgilib.auxiliary_power_uninitialize() 

 

 

@pytest.mark.parametrize("verbose", verbosity) 

def test_auxiliary_power_trigger_calibration(verbose): 

"""test_auxiliary_power_trigger_calibration. 

 

DGILibAuxiliary.auxiliary_power_trigger_calibration 

""" 

with DGILib(verbose=verbose) as dgilib: 

dgilib.power_hndl = dgilib.auxiliary_power_initialize() 

assert dgilib.auxiliary_power_trigger_calibration( 

dgilib.auxiliary_power_get_circuit_type()) is None 

dgilib.auxiliary_power_uninitialize() 

 

 

@pytest.mark.parametrize("verbose", verbosity) 

def test_auxiliary_power_get_calibration(verbose): 

"""test_auxiliary_power_get_calibration. 

 

DGILibAuxiliary.auxiliary_power_get_calibration 

""" 

with DGILib(verbose=verbose) as dgilib: 

dgilib.power_hndl = dgilib.auxiliary_power_initialize() 

calibration_data = dgilib.auxiliary_power_get_calibration() 

assert len(calibration_data) < NUM_CALIBRATION 

assert isinstance(calibration_data, list) 

dgilib.auxiliary_power_uninitialize() 

 

 

@pytest.mark.parametrize("verbose", verbosity) 

def test_auxiliary_power_get_status(verbose): 

"""test_auxiliary_power_get_status. 

 

DGILibAuxiliary.auxiliary_power_get_status 

""" 

with DGILib(verbose=verbose) as dgilib: 

dgilib.power_hndl = dgilib.auxiliary_power_initialize() 

assert dgilib.auxiliary_power_get_status() in ( 

IDLE, RUNNING, DONE, CALIBRATING, INIT_FAILED, OVERFLOWED, 

USB_DISCONNECTED, CALIBRATION_FAILED) 

dgilib.auxiliary_power_uninitialize() 

 

 

@pytest.mark.parametrize("channel, power_type", [ 

(CHANNEL_A, POWER_CURRENT), (CHANNEL_B, POWER_CURRENT), 

(CHANNEL_A, POWER_VOLTAGE), (CHANNEL_B, POWER_VOLTAGE), 

(CHANNEL_A, POWER_RANGE), (CHANNEL_B, POWER_RANGE)]) 

@pytest.mark.parametrize("mode, parameter", [(0, 0), (1, 1), ]) 

@pytest.mark.parametrize("verbose", verbosity) 

def test_auxiliary_power_start_stop(channel, power_type, mode, parameter, 

verbose): 

"""test_auxiliary_power_start_stop. 

 

DGILibAuxiliary.auxiliary_power_start 

DGILibAuxiliary.auxiliary_power_stop 

""" 

with DGILib(verbose=verbose) as dgilib: 

dgilib.power_hndl = dgilib.auxiliary_power_initialize() 

dgilib.auxiliary_power_register_buffer_pointers(channel, power_type) 

assert dgilib.auxiliary_power_start( 

mode=mode, parameter=parameter) is None 

assert dgilib.auxiliary_power_stop() is None 

dgilib.auxiliary_power_unregister_buffer_pointers(channel, power_type) 

dgilib.auxiliary_power_uninitialize() 

 

 

@pytest.mark.parametrize("channel, power_type", [ 

(CHANNEL_A, POWER_CURRENT), (CHANNEL_B, POWER_CURRENT), 

(CHANNEL_A, POWER_VOLTAGE), (CHANNEL_B, POWER_VOLTAGE), 

(CHANNEL_A, POWER_RANGE), (CHANNEL_B, POWER_RANGE)]) 

@pytest.mark.parametrize("verbose", verbosity) 

def test_auxiliary_power_lock_data_for_reading_copy_data_free_data( 

channel, power_type, verbose): 

"""test_auxiliary_power_lock_data_for_reading_copy_data_free_data. 

 

DGILibAuxiliary.auxiliary_power_lock_data_for_reading 

DGILibAuxiliary.auxiliary_power_copy_data 

DGILibAuxiliary.auxiliary_power_free_data 

""" 

with DGILib(verbose=verbose) as dgilib: 

dgilib.power_hndl = dgilib.auxiliary_power_initialize() 

dgilib.auxiliary_power_register_buffer_pointers( 

channel, power_type) 

dgilib.auxiliary_power_start() 

assert dgilib.auxiliary_power_lock_data_for_reading() is None 

powerTimestamp, powerBuffer = dgilib.auxiliary_power_copy_data( 

channel, power_type) 

assert len(powerTimestamp) == len(powerBuffer) 

assert len(powerTimestamp) < BUFFER_SIZE 

assert isinstance(powerTimestamp, list) 

assert isinstance(powerBuffer, list) 

assert dgilib.auxiliary_power_free_data() is None 

dgilib.auxiliary_power_stop() 

dgilib.auxiliary_power_unregister_buffer_pointers( 

channel, power_type) 

dgilib.auxiliary_power_uninitialize()