Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions options.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ def __str__ (self):
self.UNITS_DEFAULT))

def OptionWidget(name, v, s, on_change):
if v is None:
# A queue default that is present but unset arrives with the IPP
# "no-value" tag, which pycups returns as None. Treat it as empty so
# the conversions below take their existing unconvertible-value path.
v = ""
if isinstance(v, list):
# XXX
if isinstance(s, list):
Expand Down
74 changes: 74 additions & 0 deletions test_options.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/usr/bin/python3

## system-config-printer

## Copyright (C) 2015 Red Hat, Inc.
## Author:
## Ayush Singh <ayushsinghceee@gmail.com>

## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.

## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.

## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

import os

import gi
gi.require_version('Gtk', '3.0')
import pytest

import options

has_display = bool(os.environ.get('DISPLAY') or
os.environ.get('WAYLAND_DISPLAY'))
pytestmark = pytest.mark.skipif(not has_display,
reason="needs a GTK display connection")

NAME = "job-cancel-after"
RANGE = (0, 2147483647)


def on_change(option):
pass


def test_value_from_cups():
option = options.OptionWidget(NAME, 10800, RANGE, on_change)
assert isinstance(option, options.OptionNumeric)
assert option.get_current_value() == 10800
assert not option.is_changed()


def test_boundary_value():
option = options.OptionWidget(NAME, 0, RANGE, on_change)
assert isinstance(option, options.OptionNumeric)
assert option.get_current_value() == 0
assert not option.is_changed()


def test_no_value_with_range_supported():
"""A queue default sent with the IPP 'no-value' tag becomes None."""
option = options.OptionWidget(NAME, None, RANGE, on_change)
assert option.get_current_value() == ""
assert not option.is_changed()


def test_no_value_without_supported():
option = options.OptionWidget(NAME, None, "", on_change)
assert isinstance(option, options.OptionText)
assert option.get_current_value() == ""
assert not option.is_changed()


def test_no_value_with_supported_choices():
option = options.OptionWidget(NAME, None, ['none', 'day-time'], on_change)
assert isinstance(option, options.OptionSelectOne)
Loading