import unittest

import steamvr.steamvr
from steamvr.steamvr import SteamVR, load_steamvr_vrsettings
from unittest.mock import patch


class TestSteamVR(unittest.TestCase):
    def test_init(self):
        vr = SteamVR()

    @patch.object(SteamVR, "__enter__")
    @patch.object(SteamVR, "__exit__")
    def test_with_calls_start_stop(self, start, stop):
        with SteamVR() as vr:
            pass
        start.assert_called_once()
        stop.assert_called_once()

    def test_set_ipd(self):
        vr = SteamVR()
        vr.set_ipd(68)
        c = load_steamvr_vrsettings()
        self.assertEqual(c['steamvr']['ipdOffset'], 0.005)

        vr.set_ipd(0)
        c = load_steamvr_vrsettings()
        self.assertEqual(c['steamvr']['ipdOffset'], -0.063)
