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

"""This module holds the automated tests for atprogram.""" 

 

from atprogram.atprogram import (atprogram, get_device_info, get_project_size) 

from os import path, getcwd 

import pytest 

 

project_path = path.join(getcwd(), "UnitTest", "UnitTest") 

 

 

def test_atprogram_simple(): 

"""test_atprogram_simple.""" 

assert not atprogram(project_path=project_path, 

clean=True, build=True, program=True) 

 

 

# @pytest.mark.parametrize("verbose", (0, 3)) 

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

# @pytest.mark.parametrize("clean", (True, False)) 

@pytest.mark.parametrize("clean", (False,)) 

@pytest.mark.parametrize("build", (True, False)) 

@pytest.mark.parametrize("erase, program", 

[(False, False), (True, False), (True, True)]) 

@pytest.mark.parametrize("verify", (False,)) 

# @pytest.mark.parametrize("verify", 

# (pytest.param(True, marks=pytest.mark.xfail), False)) 

@pytest.mark.parametrize("return_output", (True, False)) 

@pytest.mark.parametrize("dry_run", (True, False)) 

def test_atprogram( 

verbose, clean, build, erase, program, verify, return_output, dry_run): 

"""test_atprogram.""" 

result = atprogram( 

project_path=project_path, verbose=verbose, clean=clean, build=build, 

erase=erase, program=program, verify=verify, 

return_output=return_output, dry_run=dry_run) 

assert not result or (return_output and result[-1] == '0') 

 

 

@pytest.mark.parametrize("make_command, atprogram_command", [ 

("--version", "--version"), 

(None, "--version"), 

("--version", None), 

pytest.param(None, None, marks=pytest.mark.xfail( 

raises=ValueError), strict=True)]) 

def test_atprogram_command(make_command, atprogram_command): 

"""test_atprogram_command.""" 

assert 0 == atprogram(make_command=make_command, 

atprogram_command=atprogram_command) 

 

 

def test_get_device_info(): 

"""test_get_device_info.""" 

info = get_device_info(verbose=2) 

assert isinstance(info, dict) 

assert info.keys() == set(('Target voltage', 'Device information', 

'Memory Information')) 

assert 'Name' in info['Device information'] 

assert info['Memory Information'].keys() == set((['base', 'fuses'])) 

 

 

def test_get_project_size(): 

"""test_get_project_size.""" 

atprogram(project_path=project_path, clean=False, build=True, 

erase=False, program=False, verify=False) 

size = get_project_size(project_path, verbose=2) 

assert isinstance(size, dict) 

size_keys = ('text', 'data', 'bss', 'dec', 'hex', 'filename') 

assert size.keys() == set(size_keys) 

for key in size_keys[:-1]: 

assert isinstance(size[key], int) 

 

 

def test_atprogram_invalid_command(): 

"""test_atprogram_not_a_command.""" 

assert atprogram(atprogram_command="invalid_command")