Пример #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
 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
    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
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
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
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
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
 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
    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
 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
 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
 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
    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
    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
 def test_create_file_with_none_filename_throws_type_error(self):
     with pytest.raises(TypeError):
         path.get_or_create_file(None)
Пример #21
0
 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
 def test_create_file_with_none_filename_throws_value_error(self):
     with self.assertRaises(ValueError):
         path.get_or_create_file(None)
Пример #24
0
 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
    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
 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')