Skip to content

Commit 4499afd

Browse files
committed
Unit tests for FunctionNow
1 parent ce31ada commit 4499afd

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from s2e2.error import ExpressionError
2+
from s2e2.functions.function_now import FunctionNow
3+
4+
import datetime
5+
import pytest
6+
7+
8+
class TestFunctionNow:
9+
10+
def setup_class(self):
11+
self.function = FunctionNow()
12+
13+
14+
def teardown_class(self):
15+
self.function = None
16+
17+
18+
def test_positive_stack_size(self):
19+
stack = []
20+
self.function.invoke(stack)
21+
assert len(stack) == 1
22+
23+
24+
def test_positive_result_type(self):
25+
stack = []
26+
self.function.invoke(stack)
27+
assert isinstance(stack[0], datetime.datetime)
28+
29+
30+
def test_positive_result_value(self):
31+
stack = []
32+
self.function.invoke(stack)
33+
34+
now = datetime.datetime.utcnow()
35+
function_result = stack[0]
36+
MAX_DIFF_IN_SECONDS = 2
37+
38+
assert now >= function_result
39+
assert (now - function_result).seconds < MAX_DIFF_IN_SECONDS
40+
41+
42+
def test_positive_more_arguments_stack_size(self):
43+
stack = [False, 'A', 'B']
44+
self.function.invoke(stack)
45+
assert len(stack) == 4

0 commit comments

Comments
 (0)