<commit_before># -*- coding: utf-8 -*-
'''Test model module

@author: moschlar
'''

from datetime import datetime

from sqlalchemy import Column, ForeignKey
from sqlalchemy.types import Integer, Unicode, DateTime, Boolean, Enum, Float, PickleType
from sqlalchemy.orm import relationship, backref, deferred
from sqlalchemy.sql import desc

from sauce.model import DeclarativeBase

class Test(DeclarativeBase):
    __tablename__ = 'tests'
    
    id = Column(Integer, primary_key=True)
    
    visible = Column(Boolean, nullable=False, default=False)
    '''Whether test is shown to user or not'''
    
    input_type = Column(Enum('stdin', 'file'), nullable=False, default='stdin')
    '''Input data type'''
    output_type = Column(Enum('stdout', 'file'), nullable=False, default='stdout')
    '''Output data type'''
    
    input_filename = Column(Unicode(255))
    '''Input data filename'''
    output_filename = Column(Unicode(255))
    '''Output data filename'''
    
    argv = deferred(Column(Unicode(255)), group='data')
    '''Command line arguments
    
    Possible variables are:
        {path}: Absolute path to temporary working directory
        {infile}: Full path to test input file
        {outfile}: Full path to test output file
    '''
    
    input_data = deferred(Column(Unicode(10485760)), group='data')
    output_data = deferred(Column(Unicode(10485760)), group='data')
    
    _timeout = Column('timeout', Float)
    
    # Validator options
    
    # Output ignore options
    ignore_case = Column(Boolean, nullable=False, default=True)
    '''Call .upper() on output before comparison'''
    ignore_whitespace = Column(Boolean, nullable=False, default=True)
    '''Call .split() on every line of output before comparison'''
    ignore_lines = Column(Boolean, nullable=False, default=False)
    '''Call .split() on full output before comparison'''
    
    # Output parsing options
    parse_int = Column(Boolean, nullable=False, default=False)
    '''Parse every substring in output to int before comparison'''
    parse_float = Column(Boolean, nullable=False, default=False)
    '''Parse every substring in output to float before comparison'''
    
    assignment_id = Column(Integer, ForeignKey('assignments.id'), nullable=False)
    assignment = relationship('Assignment', backref=backref('tests'))
    '''Assignment this test belongs to'''
    
    teacher_id = Column(Integer, ForeignKey('teachers.id'))
    teacher = relationship('Teacher', backref=backref('tests'))
    '''Teacher who created this test'''
    
    def __unicode__(self):
        return u'Test %s' % (self.id or '')
    
    @property
    def timeout(self):
        '''Return test timeout
        
        If not set on this test, the value from the assignment is used
        '''
        return self._timeout or self.assignment.timeout

class Testrun(DeclarativeBase):
    __tablename__ = 'testruns'
    __mapper_args__ = {'order_by': desc('date')}
    <commit_msg>Issue #4: Model attribute for sorting before testing<commit_after># -*- coding: utf-8 -*-
'''Test model module

@author: moschlar
'''

from datetime import datetime

from sqlalchemy import Column, ForeignKey
from sqlalchemy.types import Integer, Unicode, DateTime, Boolean, Enum, Float, PickleType
from sqlalchemy.orm import relationship, backref, deferred
from sqlalchemy.sql import desc

from sauce.model import DeclarativeBase

class Test(DeclarativeBase):
    __tablename__ = 'tests'
    
    id = Column(Integer, primary_key=True)
    
    visible = Column(Boolean, nullable=False, default=False)
    '''Whether test is shown to user or not'''
    
    input_type = Column(Enum('stdin', 'file'), nullable=False, default='stdin')
    '''Input data type'''
    output_type = Column(Enum('stdout', 'file'), nullable=False, default='stdout')
    '''Output data type'''
    
    input_filename = Column(Unicode(255))
    '''Input data filename'''
    output_filename = Column(Unicode(255))
    '''Output data filename'''
    
    argv = deferred(Column(Unicode(255)), group='data')
    '''Command line arguments
    
    Possible variables are:
        {path}: Absolute path to temporary working directory
        {infile}: Full path to test input file
        {outfile}: Full path to test output file
    '''
    
    input_data = deferred(Column(Unicode(10485760)), group='data')
    output_data = deferred(Column(Unicode(10485760)), group='data')
    
    _timeout = Column('timeout', Float)
    
    # Validator options
    
    # Output ignore options
    ignore_case = Column(Boolean, nullable=False, default=True)
    '''Call .upper() on output before comparison'''
    ignore_whitespace = Column(Boolean, nullable=False, default=True)
    '''Call .split() on every line of output before comparison'''
    ignore_lines = Column(Boolean, nullable=False, default=False)
    '''Call .split() on full output before comparison'''
    
    # Output parsing options
    parse_int = Column(Boolean, nullable=False, default=False)
    '''Parse every substring in output to int before comparison'''
    parse_float = Column(Boolean, nullable=False, default=False)
    '''Parse every substring in output to float before comparison'''
    sort = Column(Boolean, nullable=False, default=False)
    '''Sort output and test data before comparison'''
    
    assignment_id = Column(Integer, ForeignKey('assignments.id'), nullable=False)
    assignment = relationship('Assignment', backref=backref('tests'))
    '''Assignment this test belongs to'''
    
    teacher_id = Column(Integer, ForeignKey('teachers.id'))
    teacher = relationship('Teacher', backref=backref('tests'))
    '''Teacher who created this test'''
    
    def __unicode__(self):
        return u'Test %s' % (self.id or '')
    
    @property
    def timeout(self):
        '''Return test timeout
        
        If not set on this test, the value from the assignment is used
        '''
        return self._timeout or self.assignment.timeout

class Testrun(DeclarativeBase):
    __tablename__ = 'testruns'
    __mapper_args__ = {'order_by': desc('date')}
    
{'fraction_non_alphanumeric': 0.1175988190913564, 'fraction_numerical': 0.008692799737575857, 'mean_word_length': 3.7125193199381763, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2534817', 'n_tokens_mistral': 1732, 'n_tokens_neox': 1689, 'n_words': 524}