示例#1
0
    def test_day_fragment_anchor_element(self, process):
        date = datetime.date(2019, 10, 21)
        day = Day(Month(date.year, date.month), date.day)

        markup = get_markup_for_day(day, "xhtml", date=date.strftime("%d-%m-%Y"))
        document = process(markup)

        assert r'<span id="{:%Y-%m-%d}"></span>'.format(date) in document
示例#2
0
文件: journal.py 项目: ipeikon/LaBook
    def load_day(self, new_date):
        old_date = self.date
        self.date = new_date

        if not Month.same_month(new_date, old_date) or self.month is None:
            self.month = self.get_month(self.date)
            #self.month.visited = True

        self.frame.set_date(self.month, self.date, self.day)
示例#3
0
def test_to_string():
    year_number = 2000
    month_number = 10
    day_number = 15
    month = Month(year_number, month_number)
    day = Day(month, day_number)

    str_version = "{}-{}-{:02d}".format(year_number, month_number, day_number)
    assert str(day) == str_version
示例#4
0
    def load_day(self, new_date):
        old_date = self.date
        self.date = new_date

        if not Month.same_month(new_date, old_date) or self.month is None:
            self.month = self.get_month(self.date)

        self.frame.set_date(self.month, self.date, self.day)

        self.set_frame_title()
示例#5
0
def test_hashtags():
    month = Month(2000, 10)
    day = Day(month, 20)
    assert day.hashtags == []
    day.text = "#tag"
    assert day.hashtags == ["tag"]
    day.text = "abc #tag"
    assert day.hashtags == ["tag"]
    day.text = "abc #tag_with_longer_name"
    assert day.hashtags == ["tag_with_longer_name"]
    day.text = "abc #tag def"
    assert day.hashtags == ["tag"]
示例#6
0
def test_hashtags():
    month = Month(2000, 10)
    day = Day(month, 20)
    assert day.hashtags == []
    day.text = '#tag'
    assert day.hashtags == ['tag']
    day.text = 'abc #tag'
    assert day.hashtags == ['tag']
    day.text = 'abc #tag_with_longer_name'
    assert day.hashtags == ['tag_with_longer_name']
    day.text = 'abc #tag def'
    assert day.hashtags == ['tag']
示例#7
0
    def get_month(self, date):
        '''
        Returns the corresponding month if it has previously been visited,
        otherwise a new month is created and returned
        '''

        year_and_month = dates.get_year_and_month_from_date(date)

        # Selected month has not been loaded or created yet
        if year_and_month not in self.months:
            self.months[year_and_month] = Month(date.year, date.month)

        return self.months[year_and_month]
示例#8
0
def _load_month_from_disk(path, year_number, month_number):
    '''
    Load the month file at path and return a month object

    If an error occurs, return None
    '''
    try:
        # Try to read the contents of the file
        with codecs.open(path, 'rb', encoding='utf-8') as month_file:
            logging.debug('Loading file "%s"' % path)
            month_contents = yaml.load(month_file, Loader=Loader)
            month = Month(year_number, month_number, month_contents)
            return month
    except yaml.YAMLError, exc:
        logging.error('Error in file %s:\n%s' % (path, exc))
示例#9
0
def test_compare():
    year_number = 2000
    month_number = 10
    day_number = 15
    month = Month(year_number, month_number)
    day = Day(month, day_number)

    eq_day = Day(month, day_number)
    assert(day == eq_day)

    greater_day = Day(month, day_number + 1)
    assert(day < greater_day)
    assert(day <= greater_day)

    lesser_day = Day(month, day_number - 1)
    assert(day > lesser_day)
    assert(day >= lesser_day)
示例#10
0
def _load_month_from_disk(path, year_number, month_number):
    '''
    Load the month file at path and return a month object

    If an error occurs, return None
    '''
    try:
        # Try to read the contents of the file.
        with codecs.open(path, 'rb', encoding='utf-8') as month_file:
            logging.debug('Loading file "%s"' % path)
            month_contents = yaml.load(month_file, Loader=Loader)
            month = Month(year_number, month_number, month_contents, os.path.getmtime(path))
            return month
    except yaml.YAMLError as exc:
        logging.error('Error in file %s:\n%s' % (path, exc))
    except IOError:
        # If that fails, there is nothing to load, so just display an error message.
        logging.error('Error: The file %s could not be read' % path)
    except Exception:
        logging.error('An error occured while reading %s:' % path)
        raise
    # If we continued here, the possibly corrupted file would be overwritten.
    sys.exit(1)
示例#11
0
 def __init__(self, year, month, day):
     import_month = Month(year, month)
     Day.__init__(self, import_month, day)