<commit_before># pylint: disable=no-member
from sentinels import NOTHING

from .api_object import APIObject
from .archiveable import Archiveable
from .commentable import Commentable
from .error_container import ErrorContainer
from .related_entity_container import RelatedEntityContainer
from .warning_container import WarningContainer
from .lazy_query import LazyQuery
from .metadata_holder import MetadataHolder


class Session(APIObject, MetadataHolder, ErrorContainer, WarningContainer, Archiveable, Commentable, RelatedEntityContainer):

    def report_end(self, duration=NOTHING):
        self.client.api.call_function('report_session_end', {'id': self.id, 'duration': duration})

    def send_keepalive(self):
        self.client.api.call_function('send_keepalive', {'session_id': self.id})

    def report_test_start(self, name, file_name=NOTHING, class_name=NOTHING, test_logical_id=NOTHING, scm=NOTHING, file_hash=NOTHING, scm_revision=NOTHING, scm_dirty=NOTHING, is_interactive=NOTHING, variation=NOTHING):
        return self.client.api.call_function(
            'report_test_start',
            {'session_id': self.id,
             'name': name,
             'scm': scm,
             'file_hash': file_hash,
             'scm_revision': scm_revision,
             'scm_dirty': scm_dirty,
             'class_name': class_name,
             'file_name': file_name,
             'is_interactive': is_interactive,
             'variation': variation,
             'test_logical_id': test_logical_id})


    def report_in_pdb(self):
        self.client.api.call_function('report_in_pdb', {'session_id': self.id})

    def report_not_in_pdb(self):
        self.client.api.call_function('report_not_in_pdb', {'session_id': self.id})

    def add_subject(self, name, product=NOTHING, version=NOTHING, revision=NOTHING):
        return self.client.api.call_function(
            'add_subject',
            {'session_id': self.id, 'name': name, 'product': product, 'version': version, 'revision': revision})

    def edit_status(self, status):
        return self.client.api.call_function('edit_session_status', {'id': self.id, 'status': status})

    def query_tests(self):
        """Queries tests of the current session

        :rtype: A lazy query object
        """
        return LazyQuery(self.client, '/rest/sessions/{0}/tests'.format(self.id))<commit_msg>Add option to specify test metadata on test start<commit_after># pylint: disable=no-member
from sentinels import NOTHING

from .api_object import APIObject
from .archiveable import Archiveable
from .commentable import Commentable
from .error_container import ErrorContainer
from .related_entity_container import RelatedEntityContainer
from .warning_container import WarningContainer
from .lazy_query import LazyQuery
from .metadata_holder import MetadataHolder


class Session(APIObject, MetadataHolder, ErrorContainer, WarningContainer, Archiveable, Commentable, RelatedEntityContainer):

    def report_end(self, duration=NOTHING):
        self.client.api.call_function('report_session_end', {'id': self.id, 'duration': duration})

    def send_keepalive(self):
        self.client.api.call_function('send_keepalive', {'session_id': self.id})

    def report_test_start(self, name, file_name=NOTHING, class_name=NOTHING, test_logical_id=NOTHING, scm=NOTHING, file_hash=NOTHING, scm_revision=NOTHING, scm_dirty=NOTHING, is_interactive=NOTHING, variation=NOTHING, metadata=NOTHING):


        params = {'session_id': self.id,
             'name': name,
             'scm': scm,
             'file_hash': file_hash,
             'scm_revision': scm_revision,
             'scm_dirty': scm_dirty,
             'class_name': class_name,
             'file_name': file_name,
             'is_interactive': is_interactive,
             'variation': variation,
             'test_logical_id': test_logical_id}

        if metadata is not NOTHING:
            supports_inline_metadata = (self.client.api.info().endpoints.report_test_start.version >= 2)

            if supports_inline_metadata:
                params['metadata'] = metadata

        returned = self.client.api.call_function(
            'report_test_start', params
        )

        if metadata is not NOTHING and not supports_inline_metadata:
            returned.set_metadata_dict(metadata)

        return returned


    def report_in_pdb(self):
        self.client.api.call_function('report_in_pdb', {'session_id': self.id})

    def report_not_in_pdb(self):
        self.client.api.call_function('report_not_in_pdb', {'session_id': self.id})

    def add_subject(self, name, product=NOTHING, version=NOTHING, revision=NOTHING):
        return self.client.api.call_function(
            'add_subject',
            {'session_id': self.id, 'name': name, 'product': product, 'version': version, 'revision': revision})

    def edit_status(self, status):
        return self.client.api.call_function('edit_session_status', {'id': self.id, 'status': status})

    def query_tests(self):
        """Queries tests of the current session

        :rtype: A lazy query object
        """
        return LazyQuery(self.client, '/rest/sessions/{0}/tests'.format(self.id))
{'fraction_non_alphanumeric': 0.10666153253754332, 'fraction_numerical': 0.0005775895263765884, 'mean_word_length': 3.5292066259808195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7179509', 'n_tokens_mistral': 1587, 'n_tokens_neox': 1542, 'n_words': 335}