File: test_datetime.py

package info (click to toggle)
python-briefcase 0.3.22-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,300 kB
  • sloc: python: 59,405; makefile: 57
file content (48 lines) | stat: -rw-r--r-- 1,421 bytes parent folder | download | duplicates (2)
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
import subprocess
from datetime import datetime
from unittest.mock import Mock

import pytest

from briefcase.exceptions import BriefcaseCommandError


@pytest.mark.parametrize(
    "device_output, expected_datetime",
    [
        ("2023-07-12 09:28:04", datetime(2023, 7, 12, 9, 28, 4)),
        ("2023-07-12 09:28:04\n", datetime(2023, 7, 12, 9, 28, 4)),
        ("2023-7-12 9:28:04", datetime(2023, 7, 12, 9, 28, 4)),
        ("2023-12-2 14:28:04", datetime(2023, 12, 2, 14, 28, 4)),
    ],
)
def test_datetime_success(adb, device_output, expected_datetime):
    """adb.datetime() returns `datetime` for device."""
    adb.run = Mock(return_value=device_output)

    assert adb.datetime() == expected_datetime
    adb.run.assert_called_once_with("shell", "date", "+'%Y-%m-%d %H:%M:%S'")


def test_datetime_failure_call(adb):
    """adb.datetime() fails in subprocess call."""
    adb.run = Mock(
        side_effect=subprocess.CalledProcessError(returncode=1, cmd="adb shell ...")
    )

    with pytest.raises(
        BriefcaseCommandError,
        match="Error obtaining device date/time.",
    ):
        adb.datetime()


def test_datetime_failure_bad_value(adb):
    """adb.datetime() fails in output conversion."""
    adb.run = Mock(return_value="the date is jan 1 1970")

    with pytest.raises(
        BriefcaseCommandError,
        match="Error obtaining device date/time.",
    ):
        adb.datetime()