<commit_before># No shebang line, this module is meant to be imported
#
# Copyright 2014 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import datetime

# test class must be loaded first
from pyfarm.master.testutil import BaseTestCase
BaseTestCase.build_environment()

from pyfarm.core.enums import WorkState
from pyfarm.master.application import db
from pyfarm.models.task import Task


class TestTask(BaseTestCase):
    def test_insert(self):
        now = datetime.utcnow()
        task = Task(
            state=WorkState.DONE,
            priority=404,
            time_started=now,
            frame=1,
            last_error="foobar")
        db.session.add(task)
        db.session.commit()
        task_id = task.id
        db.session.remove()
        searched = Task.query.filter_by(id=task_id).first()
        self.assertIsNotNone(searched)
        self.assertEqual(searched.state, WorkState.DONE)
        self.assertEqual(searched.priority, 404)
        self.assertEqual(searched.time_started, now)
        self.assertEqual(searched.attempts, 0)
        self.assertEqual(searched.frame, 1)
        self.assertEqual(searched.last_error, "foobar")

    def test_increment_attempts(self):
        task = Task(frame=1)
        db.session.add(task)
        db.session.commit()
        self.assertEqual(task.attempts, 0)
        task.state = WorkState.RUNNING
        task.state = WorkState.DONE
        self.assertEqual(task.attempts, 1)
        task.state = WorkState.RUNNING
        task.state = WorkState.FAILED
        self.assertEqual(task.attempts, 2)
        task.state = WorkState.RUNNING
        task.state = WorkState.FAILED
        task.state = WorkState.RUNNING
        self.assertEqual(task.attempts, 4)
        task.state = WorkState.RUNNING
        task.state = WorkState.RUNNING
        self.assertEqual(task.attempts, 4)
<commit_msg>last_error would be reset<commit_after># No shebang line, this module is meant to be imported
#
# Copyright 2014 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from datetime import datetime

# test class must be loaded first
from pyfarm.master.testutil import BaseTestCase
BaseTestCase.build_environment()

from pyfarm.core.enums import WorkState
from pyfarm.master.application import db
from pyfarm.models.task import Task


class TestTask(BaseTestCase):
    def test_insert(self):
        now = datetime.utcnow()
        task = Task(
            state=WorkState.DONE,
            priority=404,
            time_started=now,
            frame=1,
            last_error="foobar")
        db.session.add(task)
        db.session.commit()
        task_id = task.id
        db.session.remove()
        searched = Task.query.filter_by(id=task_id).first()
        self.assertIsNotNone(searched)
        self.assertEqual(searched.state, WorkState.DONE)
        self.assertEqual(searched.priority, 404)
        self.assertEqual(searched.time_started, now)
        self.assertEqual(searched.attempts, 0)
        self.assertEqual(searched.frame, 1)

    def test_increment_attempts(self):
        task = Task(frame=1)
        db.session.add(task)
        db.session.commit()
        self.assertEqual(task.attempts, 0)
        task.state = WorkState.RUNNING
        task.state = WorkState.DONE
        self.assertEqual(task.attempts, 1)
        task.state = WorkState.RUNNING
        task.state = WorkState.FAILED
        self.assertEqual(task.attempts, 2)
        task.state = WorkState.RUNNING
        task.state = WorkState.FAILED
        task.state = WorkState.RUNNING
        self.assertEqual(task.attempts, 4)
        task.state = WorkState.RUNNING
        task.state = WorkState.RUNNING
        self.assertEqual(task.attempts, 4)

{'fraction_non_alphanumeric': 0.08683651804670912, 'fraction_numerical': 0.009766454352441613, 'mean_word_length': 2.830081300813008, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1671517', 'n_tokens_mistral': 1395, 'n_tokens_neox': 1355, 'n_words': 373}