1# Copyright 2022 The Pigweed Authors 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); you may not 4# use this file except in compliance with the License. You may obtain a copy of 5# the License at 6# 7# https://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12# License for the specific language governing permissions and limitations under 13# the License. 14"""Tests for pw_ide.commands""" 15 16import logging 17import os 18import unittest 19 20from pw_cli.status_reporter import LoggingStatusReporter 21from pw_ide.commands import _make_working_dir 22from pw_ide.settings import PW_IDE_DIR_NAME 23 24from test_cases import PwIdeTestCase 25 26_LOG = logging.getLogger(__package__) 27 28 29class TestMakeWorkingDir(PwIdeTestCase): 30 """Tests _make_working_dir""" 31 32 def test_does_not_exist_creates_dir(self): 33 settings = self.make_ide_settings(working_dir=PW_IDE_DIR_NAME) 34 self.assertFalse(settings.working_dir.exists()) 35 _make_working_dir( 36 reporter=LoggingStatusReporter(_LOG), settings=settings 37 ) 38 self.assertTrue(settings.working_dir.exists()) 39 40 def test_does_exist_is_idempotent(self): 41 settings = self.make_ide_settings(working_dir=PW_IDE_DIR_NAME) 42 _make_working_dir( 43 reporter=LoggingStatusReporter(_LOG), settings=settings 44 ) 45 modified_when_1 = os.path.getmtime(settings.working_dir) 46 _make_working_dir( 47 reporter=LoggingStatusReporter(_LOG), settings=settings 48 ) 49 modified_when_2 = os.path.getmtime(settings.working_dir) 50 self.assertEqual(modified_when_1, modified_when_2) 51 52 53if __name__ == '__main__': 54 unittest.main() 55