
from pathlib import Path

import pytest

from byceps.services.user_avatar import service as user_avatar_service
from byceps.util.image.models import ImageType


@pytest.mark.parametrize(
    'image_extension, image_type',
    [
        ('jpeg', ImageType.jpeg),
        ('png', ImageType.png),
    ],
)
def test_path(data_path, site_app, user, image_extension, image_type):
    with Path(f'tests/fixtures/images/image.{image_extension}').open('rb') as f:
        avatar_id = user_avatar_service.update_avatar_image(
            user.id, f, {image_type}
        )

    avatar = user_avatar_service.get_db_avatar(avatar_id)
    expected_filename = f'{avatar.id}.{image_extension}'

    assert avatar.path == data_path / 'global/users/avatars' / expected_filename


from pathlib import Path

import pytest

from byceps.services.user_avatar import service as user_avatar_service
from byceps.util.image.models import ImageType


@pytest.mark.parametrize(
    'image_extension, image_type',
    [
        ('jpeg', ImageType.jpeg),
        ('png', ImageType.png),
    ],
)
def test_path(data_path, site_app, user, image_extension, image_type):
    with Path(f'tests/fixtures/images/image.{image_extension}').open('rb') as f:
        avatar_id = user_avatar_service.update_avatar_image(
            user.id, f, {image_type}
        )

    avatar = user_avatar_service.get_db_avatar(avatar_id)
    expected_filename = f'{avatar.id}.{image_extension}'
    expected = data_path / 'global' / 'users' / 'avatars' / expected_filename

    assert avatar.path == expected

Use `/` operator to assemble path
Use `/` operator to assemble path

  
  from pathlib import Path
  
  import pytest
  
  from byceps.services.user_avatar import service as user_avatar_service
  from byceps.util.image.models import ImageType
  
  
  @pytest.mark.parametrize(
      'image_extension, image_type',
      [
          ('jpeg', ImageType.jpeg),
          ('png', ImageType.png),
      ],
  )
  def test_path(data_path, site_app, user, image_extension, image_type):
      with Path(f'tests/fixtures/images/image.{image_extension}').open('rb') as f:
          avatar_id = user_avatar_service.update_avatar_image(
              user.id, f, {image_type}
          )
  
      avatar = user_avatar_service.get_db_avatar(avatar_id)
      expected_filename = f'{avatar.id}.{image_extension}'
+     expected = data_path / 'global' / 'users' / 'avatars' / expected_filename
  
-     assert avatar.path == data_path / 'global/users/avatars' / expected_filename
+     assert avatar.path == expected
  
Use `/` operator to assemble path
## Code Before:

from pathlib import Path

import pytest

from byceps.services.user_avatar import service as user_avatar_service
from byceps.util.image.models import ImageType


@pytest.mark.parametrize(
    'image_extension, image_type',
    [
        ('jpeg', ImageType.jpeg),
        ('png', ImageType.png),
    ],
)
def test_path(data_path, site_app, user, image_extension, image_type):
    with Path(f'tests/fixtures/images/image.{image_extension}').open('rb') as f:
        avatar_id = user_avatar_service.update_avatar_image(
            user.id, f, {image_type}
        )

    avatar = user_avatar_service.get_db_avatar(avatar_id)
    expected_filename = f'{avatar.id}.{image_extension}'

    assert avatar.path == data_path / 'global/users/avatars' / expected_filename

## Instruction:
Use `/` operator to assemble path
## Code After:

from pathlib import Path

import pytest

from byceps.services.user_avatar import service as user_avatar_service
from byceps.util.image.models import ImageType


@pytest.mark.parametrize(
    'image_extension, image_type',
    [
        ('jpeg', ImageType.jpeg),
        ('png', ImageType.png),
    ],
)
def test_path(data_path, site_app, user, image_extension, image_type):
    with Path(f'tests/fixtures/images/image.{image_extension}').open('rb') as f:
        avatar_id = user_avatar_service.update_avatar_image(
            user.id, f, {image_type}
        )

    avatar = user_avatar_service.get_db_avatar(avatar_id)
    expected_filename = f'{avatar.id}.{image_extension}'
    expected = data_path / 'global' / 'users' / 'avatars' / expected_filename

    assert avatar.path == expected
