Nekmo/telegram-upload

View on GitHub

Showing 34 of 34 total issues

File test_caption_formatter.py has 348 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import sys
import unittest
from pathlib import Path
from unittest.mock import patch, MagicMock, mock_open, call

Severity: Minor
Found in tests/test_caption_formatter.py - About 4 hrs to fix

    File telegram_upload_client.py has 319 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import asyncio
    import hashlib
    import os
    import time
    from typing import Iterable, Optional
    Severity: Minor
    Found in telegram_upload/client/telegram_upload_client.py - About 3 hrs to fix

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          @patch('telegram_upload.upload_files.os.path.getsize', return_value=USER_MAX_FILE_SIZE - 1)
          @patch('telegram_upload.upload_files.File')
          def test_small_file(self, m1, m2):
              self.assertEqual(len(list(NoLargeFiles(MagicMock(max_file_size=USER_MAX_FILE_SIZE), ['foo']))), 1)
      Severity: Major
      Found in tests/test_files.py and 1 other location - About 2 hrs to fix
      tests/test_files.py on lines 88..91

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 60.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

          @patch('telegram_upload.upload_files.os.path.getsize', return_value=USER_MAX_FILE_SIZE - 1)
          @patch('telegram_upload.upload_files.File')
          def test_small_file(self, m1, m2):
              self.assertEqual(len(list(SplitFiles(MagicMock(max_file_size=USER_MAX_FILE_SIZE), ['foo']))), 1)
      Severity: Major
      Found in tests/test_files.py and 1 other location - About 2 hrs to fix
      tests/test_files.py on lines 60..63

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 60.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      TestFilePath has 24 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class TestFilePath(unittest.TestCase):
          """Test the FilePath class."""
      
          def setUp(self) -> None:
              """Set up the test case."""
      Severity: Minor
      Found in tests/test_caption_formatter.py - About 2 hrs to fix

        File caption_formatter.py has 271 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        import _string
        import datetime
        import hashlib
        import mimetypes
        import os
        Severity: Minor
        Found in telegram_upload/caption_formatter.py - About 2 hrs to fix

          FileMixin has 23 functions (exceeds 20 allowed). Consider refactoring.
          Open

          class FileMixin:
          
              def _calculate_hash(self, hash_calculator: Any) -> str:
                  with open(str(self), "rb") as f:
                      # Read and update hash string value in blocks
          Severity: Minor
          Found in telegram_upload/caption_formatter.py - About 2 hrs to fix

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                @patch('telegram_upload.upload_files.scantree', return_value=[])
                @patch('telegram_upload.upload_files.os.path.isdir', return_value=False)
                def test_one_file(self, m1, m2):
                    self.assertEqual(list(RecursiveFiles(MagicMock(), ['foo'])), ['foo'])
            Severity: Major
            Found in tests/test_files.py and 1 other location - About 2 hrs to fix
            tests/test_files.py on lines 48..51

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 52.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Similar blocks of code found in 2 locations. Consider refactoring.
            Open

                @patch('telegram_upload.upload_files.scantree', return_value=[])
                @patch('telegram_upload.upload_files.os.path.isdir', return_value=False)
                def test_one_file(self, m1, m2):
                    self.assertEqual(list(NoDirectoriesFiles(MagicMock(), ['foo'])), ['foo'])
            Severity: Major
            Found in tests/test_files.py and 1 other location - About 2 hrs to fix
            tests/test_files.py on lines 30..33

            Duplicated Code

            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

            Tuning

            This issue has a mass of 52.

            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

            Refactorings

            Further Reading

            Function upload has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
            Open

            def upload(files, to, config, delete_on_success, print_file_id, force_file, forward, directories, large_files, caption,
                       no_thumbnail, thumbnail_file, proxy, album, interactive, sort):
                """Upload one or more files to Telegram using your personal account.
                The maximum file size is 2 GiB for free users and 4 GiB for premium accounts.
                By default, they will be saved in your saved messages.
            Severity: Minor
            Found in telegram_upload/management.py - About 2 hrs to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function upload has 16 arguments (exceeds 4 allowed). Consider refactoring.
            Open

            def upload(files, to, config, delete_on_success, print_file_id, force_file, forward, directories, large_files, caption,
            Severity: Major
            Found in telegram_upload/management.py - About 2 hrs to fix

              Function send_files has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  def send_files(self, entity, files: Iterable[File], delete_on_success=False, print_file_id=False,
                                 forward=(), send_as_media: bool = False):
                      has_files = False
                      messages = []
                      for file in files:
              Severity: Minor
              Found in telegram_upload/client/telegram_upload_client.py - About 1 hr to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function for_humans has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
              Open

                  def for_humans(self) -> str:
                      words = ["year", "day", "hour", "minute", "second"]
              
                      if not self.seconds:
                          return "now"
              Severity: Minor
              Found in telegram_upload/caption_formatter.py - About 1 hr to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Consider simplifying this complex logical expression.
              Open

                          if (has_func and obj.__func__ in AUTHORIZED_METHODS) or \
                                  (has_self and isinstance(obj.__self__, str) and obj.__name__ in AUTHORIZED_STRING_METHODS) or \
                                  (has_self and isinstance(obj.__self__, datetime.datetime)
                                   and obj.__name__ in AUTHORIZED_DT_METHODS):
                              obj = obj()
              Severity: Critical
              Found in telegram_upload/caption_formatter.py - About 1 hr to fix

                Function start has 9 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    def start(
                Severity: Major
                Found in telegram_upload/client/telegram_manager_client.py - About 1 hr to fix

                  Function get_iterator has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def get_iterator(self) -> Iterator[DownloadFile]:
                          """Get an iterator with the download files. This method applies the join strategy and
                          joins the files after download it.
                          """
                          current_join_strategy: Optional[JoinStrategyBase] = None
                  Severity: Minor
                  Found in telegram_upload/download_files.py - About 1 hr to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Function get_file_display_name has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                  Open

                  def get_file_display_name(message):
                      display_name_parts = []
                      is_document = message.document
                      if is_document and message.document.mime_type:
                          display_name_parts.append(message.document.mime_type.split('/')[0])
                  Severity: Minor
                  Found in telegram_upload/management.py - About 1 hr to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Function get_field has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def get_field(self, field_name: str, args: Sequence[Any], kwargs: Mapping[str, Any]) -> Any:
                          try:
                              if "._" in field_name:
                                  raise TypeError(f'Access to private property in {field_name}')
                              obj, first = super().get_field(field_name, args, kwargs)
                  Severity: Minor
                  Found in telegram_upload/caption_formatter.py - About 55 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Function benchmark has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                  def benchmark(repeats, benchmark, parallel, results_file):
                      client = TelegramManagerClient(default_config())
                      client.start()
                      if benchmark:
                          benchmarks = [BENCHMARKS[benchmark]]
                  Severity: Minor
                  Found in docs/upload_benchmark.py - About 45 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Function get_video_thumb has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                  def get_video_thumb(file, output=None, size=200):
                      output = output or tempfile.NamedTemporaryFile(suffix='.jpg').name
                      metadata = video_metadata(file)
                      if metadata is None:
                          return
                  Severity: Minor
                  Found in telegram_upload/video.py - About 45 mins to fix

                  Cognitive Complexity

                  Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

                  A method's cognitive complexity is based on a few simple rules:

                  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
                  • Code is considered more complex for each "break in the linear flow of the code"
                  • Code is considered more complex when "flow breaking structures are nested"

                  Further reading

                  Severity
                  Category
                  Status
                  Source
                  Language