#!/usr/bin/python3
# -*- coding: utf-8 -*-

from sun.__metadata__ import __prgnam__, __version__, __author__, __about_text__
from sun.utils import Utilities


class TestMetadata:

    def test_prgnam(self):
        assert __prgnam__ == 'sun'

    def test_version_format(self):
        if __version__ == 'unknown':
            return
        parts = __version__.split('.')
        assert len(parts) == 3
        assert all(p.isdigit() for p in parts)

    def test_author(self):
        assert __author__ == 'dslackw'


class TestAbout:

    def test_about_text_contains_version(self):
        assert __version__ in __about_text__

    def test_about_text_contains_prgnam(self):
        assert 'SUN' in __about_text__


class TestConvertSizes:

    def test_bytes(self):
        assert Utilities.convert_sizes(512) == '512 B'

    def test_kilobytes(self):
        assert Utilities.convert_sizes(2048) == '2 KB'

    def test_megabytes(self):
        assert Utilities.convert_sizes(5 * 1024 * 1024) == '5 MB'

    def test_gigabytes(self):
        assert Utilities.convert_sizes(2 * 1024 * 1024 * 1024) == '2 GB'


class TestReadLocalTextFile:

    def test_existing_file(self, tmp_path):
        f = tmp_path / 'test.txt'
        f.write_text('hello world', encoding='utf-8')
        assert Utilities.read_local_text_file(f) == 'hello world'

    def test_missing_file(self, tmp_path):
        result = Utilities.read_local_text_file(tmp_path / 'missing.txt')
        assert result == ''
