• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_ide.commands import _make_working_dir, LoggingStatusReporter
21from pw_ide.settings import PW_IDE_DIR_NAME
22
23from test_cases import PwIdeTestCase
24
25_LOG = logging.getLogger(__package__)
26
27
28class TestMakeWorkingDir(PwIdeTestCase):
29    """Tests _make_working_dir"""
30
31    def test_does_not_exist_creates_dir(self):
32        settings = self.make_ide_settings(working_dir=PW_IDE_DIR_NAME)
33        self.assertFalse(settings.working_dir.exists())
34        _make_working_dir(
35            reporter=LoggingStatusReporter(_LOG), settings=settings
36        )
37        self.assertTrue(settings.working_dir.exists())
38
39    def test_does_exist_is_idempotent(self):
40        settings = self.make_ide_settings(working_dir=PW_IDE_DIR_NAME)
41        _make_working_dir(
42            reporter=LoggingStatusReporter(_LOG), settings=settings
43        )
44        modified_when_1 = os.path.getmtime(settings.working_dir)
45        _make_working_dir(
46            reporter=LoggingStatusReporter(_LOG), settings=settings
47        )
48        modified_when_2 = os.path.getmtime(settings.working_dir)
49        self.assertEqual(modified_when_1, modified_when_2)
50
51
52if __name__ == '__main__':
53    unittest.main()
54