コード例 #1
0
 def test_creating_existing_file(self):
     file_path = os.path.join(self.parent, b'test')
     path.get_or_create_file(file_path)
     created = path.get_or_create_file(file_path)
     self.assert_(os.path.exists(file_path))
     self.assert_(os.path.isfile(file_path))
     self.assertEqual(created, file_path)
コード例 #2
0
ファイル: test_path.py プロジェクト: mopidy/mopidy
 def test_creating_existing_file(self):
     file_path = os.path.join(self.parent, b'test')
     path.get_or_create_file(file_path)
     created = path.get_or_create_file(file_path)
     self.assert_(os.path.exists(file_path))
     self.assert_(os.path.isfile(file_path))
     self.assertEqual(created, file_path)
コード例 #3
0
ファイル: test_path.py プロジェクト: zwl1671/mopidy
    def test_creating_existing_file(self):
        file_path = self.parent / "test"
        path.get_or_create_file(str(file_path))

        created = path.get_or_create_file(str(file_path))

        assert file_path.is_file()
        assert created == file_path
コード例 #4
0
ファイル: __main__.py プロジェクト: SeeSpotRun/mopidy
def create_initial_config_file(args, extensions_data):
    """Initialize whatever the last config file is with defaults"""

    config_file = args.config_files[-1]

    if os.path.exists(path.expand_path(config_file)):
        return

    try:
        default = config_lib.format_initial(extensions_data)
        path.get_or_create_file(config_file, mkdir=False, content=default)
        logger.info("Initialized %s with default config", config_file)
    except IOError as error:
        logger.warning("Unable to initialize %s with default config: %s", config_file, encoding.locale_decode(error))
コード例 #5
0
ファイル: __main__.py プロジェクト: vrs01/mopidy
def create_initial_config_file(args, extensions_data):
    """Initialize whatever the last config file is with defaults"""

    config_file = args.config_files[-1]

    if os.path.exists(path.expand_path(config_file)):
        return

    try:
        default = config_lib.format_initial(extensions_data)
        path.get_or_create_file(config_file, mkdir=False, content=default)
        logger.info('Initialized %s with default config', config_file)
    except IOError as error:
        logger.warning('Unable to initialize %s with default config: %s',
                       config_file, encoding.locale_decode(error))
コード例 #6
0
ファイル: __main__.py プロジェクト: bencevans/mopidy
def create_file_structures_and_config(args, extensions_data):
    path.get_or_create_dir(b'$XDG_DATA_DIR/mopidy')
    path.get_or_create_dir(b'$XDG_CONFIG_DIR/mopidy')

    # Initialize whatever the last config file is with defaults
    config_file = args.config_files[-1]
    if os.path.exists(path.expand_path(config_file)):
        return

    try:
        default = config_lib.format_initial(extensions_data)
        path.get_or_create_file(config_file, mkdir=False, content=default)
        logger.info('Initialized %s with default config', config_file)
    except IOError as error:
        logger.warning(
            'Unable to initialize %s with default config: %s',
            config_file, encoding.locale_decode(error))
コード例 #7
0
ファイル: __main__.py プロジェクト: zwl1671/mopidy
def create_initial_config_file(args, extensions_data):
    """Initialize whatever the last config file is with defaults"""

    config_file = path.expand_path(args.config_files[-1])

    if config_file.exists():
        return

    try:
        default = config_lib.format_initial(extensions_data)
        path.get_or_create_file(
            config_file,
            mkdir=False,
            content=default.encode(errors="surrogateescape"),
        )
        logger.info(f"Initialized {config_file.as_uri()} with default config")
    except OSError as exc:
        logger.warning(
            f"Unable to initialize {config_file.as_uri()} with default config: {exc}"
        )
コード例 #8
0
ファイル: test_path.py プロジェクト: mopidy/mopidy
 def test_creating_nested_file(self):
     level2_dir = os.path.join(self.parent, b'test')
     file_path = os.path.join(self.parent, b'test', b'test')
     self.assert_(not os.path.exists(level2_dir))
     self.assert_(not os.path.exists(file_path))
     created = path.get_or_create_file(file_path)
     self.assert_(os.path.exists(level2_dir))
     self.assert_(os.path.isdir(level2_dir))
     self.assert_(os.path.exists(file_path))
     self.assert_(os.path.isfile(file_path))
     self.assertEqual(created, file_path)
コード例 #9
0
ファイル: test_path.py プロジェクト: zwl1671/mopidy
    def test_creating_nested_file(self):
        level2_dir = self.parent / "test"
        file_path = self.parent / "test" / "test"
        assert not level2_dir.exists()
        assert not file_path.exists()

        created = path.get_or_create_file(str(file_path))

        assert level2_dir.is_dir()
        assert file_path.is_file()
        assert created == file_path
コード例 #10
0
 def test_creating_nested_file(self):
     level2_dir = os.path.join(self.parent, b'test')
     file_path = os.path.join(self.parent, b'test', b'test')
     self.assert_(not os.path.exists(level2_dir))
     self.assert_(not os.path.exists(file_path))
     created = path.get_or_create_file(file_path)
     self.assert_(os.path.exists(level2_dir))
     self.assert_(os.path.isdir(level2_dir))
     self.assert_(os.path.exists(file_path))
     self.assert_(os.path.isfile(file_path))
     self.assertEqual(created, file_path)
コード例 #11
0
 def test_create_dir_without_mkdir(self):
     file_path = os.path.join(self.parent, b'foo', b'bar')
     with self.assertRaises(IOError):
         path.get_or_create_file(file_path, mkdir=False)
コード例 #12
0
 def test_create_file_with_none_filename_throws_value_error(self):
     with self.assertRaises(ValueError):
         path.get_or_create_file(None)
コード例 #13
0
 def test_create_dir_with_unicode_filename_throws_value_error(self):
     with self.assertRaises(ValueError):
         file_path = compat.text_type(os.path.join(self.parent, b'test'))
         path.get_or_create_file(file_path)
コード例 #14
0
 def test_create_file_with_name_of_existing_dir_throws_ioerror(self):
     conflicting_dir = os.path.join(self.parent)
     with self.assertRaises(IOError):
         path.get_or_create_file(conflicting_dir)
コード例 #15
0
ファイル: test_path.py プロジェクト: mopidy/mopidy
 def test_create_dir_with_unicode_filename_throws_value_error(self):
     with self.assertRaises(ValueError):
         file_path = compat.text_type(os.path.join(self.parent, b'test'))
         path.get_or_create_file(file_path)
コード例 #16
0
ファイル: test_path.py プロジェクト: mopidy/mopidy
 def test_create_file_with_name_of_existing_dir_throws_ioerror(self):
     conflicting_dir = os.path.join(self.parent)
     with self.assertRaises(IOError):
         path.get_or_create_file(conflicting_dir)
コード例 #17
0
ファイル: test_path.py プロジェクト: mopidy/mopidy
 def test_create_dir_without_mkdir(self):
     file_path = os.path.join(self.parent, b'foo', b'bar')
     with self.assertRaises(IOError):
         path.get_or_create_file(file_path, mkdir=False)
コード例 #18
0
ファイル: test_path.py プロジェクト: zwl1671/mopidy
    def test_create_dir_with_bytes_content(self):
        file_path = self.parent / "test"

        created = path.get_or_create_file(str(file_path), content=b"foobar")

        assert created.read_bytes() == b"foobar"
コード例 #19
0
ファイル: test_path.py プロジェクト: zwl1671/mopidy
    def test_create_dir_without_mkdir(self):
        file_path = self.parent / "foo" / "bar"

        with pytest.raises(OSError):
            path.get_or_create_file(file_path, mkdir=False)
コード例 #20
0
ファイル: test_path.py プロジェクト: zwl1671/mopidy
 def test_create_file_with_none_filename_throws_type_error(self):
     with pytest.raises(TypeError):
         path.get_or_create_file(None)
コード例 #21
0
ファイル: test_path.py プロジェクト: mopidy/mopidy
 def test_create_dir_with_bytes_content(self):
     file_path = os.path.join(self.parent, b'test')
     created = path.get_or_create_file(file_path, content=b'foobar')
     with open(created) as fh:
         self.assertEqual(fh.read(), b'foobar')
コード例 #22
0
 def test_create_dir_with_unicode_content(self):
     file_path = os.path.join(self.parent, b'test')
     created = path.get_or_create_file(file_path, content='foobaræøå')
     with open(created) as fh:
         self.assertEqual(fh.read(), b'foobaræøå')
コード例 #23
0
ファイル: test_path.py プロジェクト: mopidy/mopidy
 def test_create_file_with_none_filename_throws_value_error(self):
     with self.assertRaises(ValueError):
         path.get_or_create_file(None)
コード例 #24
0
ファイル: test_path.py プロジェクト: zwl1671/mopidy
 def test_create_file_with_name_of_existing_dir_throws_error(self):
     with pytest.raises(OSError):
         path.get_or_create_file(self.parent)
コード例 #25
0
ファイル: test_path.py プロジェクト: zwl1671/mopidy
    def test_create_dir_with_unicode_content(self):
        file_path = self.parent / "test"

        created = path.get_or_create_file(str(file_path), content="foobaræøå")
        assert created.read_bytes() == b"foobar\xc3\xa6\xc3\xb8\xc3\xa5"
コード例 #26
0
ファイル: test_path.py プロジェクト: mopidy/mopidy
 def test_create_dir_with_unicode_content(self):
     file_path = os.path.join(self.parent, b'test')
     created = path.get_or_create_file(file_path, content='foobaræøå')
     with open(created) as fh:
         self.assertEqual(fh.read(), b'foobar\xc3\xa6\xc3\xb8\xc3\xa5')