gnome-wallpaper-slideshow 0.3 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -1,7 +1,9 @@
1
1
  require 'rake/testtask'
2
2
 
3
3
  Rake::TestTask.new do |t|
4
- t.libs << 'test'
4
+ t.libs.push "lib"
5
+ t.test_files = FileList['test/*.rb']
6
+ t.verbose = true
5
7
  end
6
8
 
7
9
  desc "Run tests"
@@ -3,6 +3,7 @@
3
3
 
4
4
  require 'gnome-wallpaper-slideshow'
5
5
  require 'gnome-wallpaper-slideshow/wallpaper'
6
+ require 'optparse'
6
7
 
7
8
  DEFAULT_EXTENSIONS = "jpg,png,jpeg"
8
9
 
@@ -13,23 +14,75 @@ def get_absolute_path(file)
13
14
  File.expand_path file
14
15
  end
15
16
 
17
+ # Parse command-line options
18
+ options = {}
16
19
 
17
- if ARGV.length < 3
18
- puts "You must specify four arguments: the image directory, the time to display each image in seconds, the transition time in seconds, and the output filename."
19
- puts "You may optionally specify a fifth argument: the list of file extensions to include. If omitted, it will default to #{DEFAULT_EXTENSIONS}"
20
- exit 1
20
+ optparse = OptionParser.new do |opts|
21
+ opts.on('-d', '--dir DIRECTORY', 'directory containing image files') do |sender|
22
+ options[:dir] = sender
23
+ end
24
+
25
+ opts.on('-t', '--time DURATION', 'amount of time to display each wallpaper in seconds') do |sender|
26
+ options[:duration] = sender
27
+ end
28
+
29
+ opts.on('-r', '--transition DURATION', 'transition time between wallpapers in seconds') do |sender|
30
+ options[:transition] = sender
31
+ end
32
+
33
+ opts.on('-f', '--filename FILENAME', 'output filename') do |sender|
34
+ options[:file] = sender
35
+ end
36
+
37
+ opts.on('-e', '--extensions EXTENSIONS', "comma-separated list of file extensions, defaults to #{DEFAULT_EXTENSIONS}") do |sender|
38
+ options[:ext] = sender
39
+ end
40
+
41
+ opts.on('-s', '--shuffle', 'Randomly shuffle the order of the wallpapers') do |sender|
42
+ options[:shuffle] = sender
43
+ end
44
+
45
+ opts.on_tail('-h', '--help', 'Show this message') do
46
+ puts opts
47
+ exit
48
+ end
49
+ end
50
+
51
+ # Ensure mandatory arguments are present
52
+ begin
53
+ optparse.parse!
54
+ mandatory = [:dir, :duration, :transition, :file]
55
+
56
+ missing = mandatory.select do |param|
57
+ options[param].nil?
58
+ end
59
+
60
+ if not missing.empty?
61
+ puts "Missing options: #{missing.join(', ')}"
62
+ puts optparse
63
+ exit
64
+ end
65
+ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
66
+ puts $!.to_s
67
+ puts optparse
68
+ exit
21
69
  end
22
70
 
23
- image_directory = get_absolute_path(ARGV[0])
24
- time = ARGV[1]
25
- transition_time = ARGV[2]
26
- output_filename = ARGV[3]
27
- extensions = ARGV[4] || DEFAULT_EXTENSIONS
71
+ image_directory = options[:dir]
72
+ time = options[:duration]
73
+ transition_time = options[:transition]
74
+ output_filename = options[:file]
75
+ extensions = options[:ext] || DEFAULT_EXTENSIONS
28
76
 
29
77
  wallpapers = Dir.glob("#{image_directory}/*.{#{extensions}}").map do |file|
30
78
  GnomeWallpaperSlideshow::Wallpaper.new get_absolute_path(file), time, transition_time
31
79
  end
32
80
 
81
+ # Randomly shuffle the wallpapers if requested
82
+ if options[:shuffle]
83
+ wallpapers.shuffle!
84
+ end
85
+
33
86
  slideshow = GnomeWallpaperSlideshow.new do
34
87
  create_new_slideshow output_filename
35
88
  start_time Time.now
@@ -12,4 +12,8 @@ class GnomeWallpaperSlideshow::Wallpaper
12
12
  @duration = duration
13
13
  @transition_time = transition_time
14
14
  end
15
+
16
+ def ==(other)
17
+ (self.filename == other.filename) && (self.duration == other.duration) && (self.transition_time == other.transition_time)
18
+ end
15
19
  end
@@ -1,58 +1,146 @@
1
- require 'test/unit'
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
2
3
  require 'gnome-wallpaper-slideshow'
3
4
 
4
- class GnomeWallpaperSlideshowTest < Test::Unit::TestCase
5
- def test_create_new_slideshow
6
- slideshow = GnomeWallpaperSlideshow.new do
5
+ describe GnomeWallpaperSlideshow do
6
+ before do
7
+ @slideshow_default = GnomeWallpaperSlideshow.new do
8
+ create_new_slideshow
9
+ end
10
+
11
+ @slideshow = GnomeWallpaperSlideshow.new do
7
12
  create_new_slideshow "xml_slideshow.xml"
13
+ start_time Time.local 2009,8,4,0,0,0
14
+ add_wallpaper (GnomeWallpaperSlideshow::Wallpaper.new "test.jpg", 100, 5)
15
+ add_wallpaper (GnomeWallpaperSlideshow::Wallpaper.new "other.jpg", 500, 3)
8
16
  end
9
17
 
10
- path = Pathname.new "xml_slideshow.xml"
11
- assert_equal path, slideshow.path
12
- end
18
+ @slideshow_existing = GnomeWallpaperSlideshow.new
13
19
 
14
- def test_create_new_slideshow_default_arg
15
- slideshow = GnomeWallpaperSlideshow.new do
16
- create_new_slideshow
20
+ # Mock out some methods to avoid reading/writing to disk
21
+ def @slideshow.write_xml(xml_string)
22
+ xml_string
23
+ end
24
+
25
+ def @slideshow_existing.load_slideshow_xml
26
+ @xml_doc = Nokogiri::XML("<?xml version=\"1.0\"?>
27
+ <background>
28
+ <starttime>
29
+ <year>2013</year>
30
+ <month>1</month>
31
+ <day>1</day>
32
+ <hour>00</hour>
33
+ <minute>00</minute>
34
+ <second>00</second>
35
+ </starttime>
36
+ <static>
37
+ <duration>100</duration>
38
+ <file>test.jpg</file>
39
+ </static>
40
+ <transition>
41
+ <duration>5</duration>
42
+ <from>test.jpg</from>
43
+ <to>other.jpg</to>
44
+ </transition>
45
+ <static>
46
+ <duration>500</duration>
47
+ <file>other.jpg</file>
48
+ </static>
49
+ <transition>
50
+ <duration>3</duration>
51
+ <from>other.jpg</from>
52
+ <to>test.jpg</to>
53
+ </transition>
54
+ </background>
55
+ ") do |config|
56
+ config.strict
57
+ end
17
58
  end
18
59
 
19
- path = Pathname.new "slideshow.xml"
20
- assert_equal path, slideshow.path
60
+ @slideshow_existing.load_slideshow "real_slideshow.xml"
21
61
  end
62
+
22
63
 
23
- def test_start_time
24
- slideshow = GnomeWallpaperSlideshow.new
64
+ it "can be created with the default output file" do
65
+ @slideshow_default.path.must_equal (Pathname.new "slideshow.xml")
66
+ end
25
67
 
26
- time = Time.local 2009,8,4,0,0,0
27
-
28
- assert_equal time, slideshow.start_time(time) # Test setting the time
29
- assert_equal time, slideshow.start_time # Test getting the time
68
+ it "can be created with a specific output file" do
69
+ @slideshow.path.must_equal (Pathname.new "xml_slideshow.xml")
30
70
  end
31
71
 
32
- def test_path
33
- slideshow = GnomeWallpaperSlideshow.new
72
+ it "can have its output path set" do
73
+ path = Pathname.new "new_slideshow.xml"
74
+ @slideshow_default.path path
75
+ @slideshow_default.path.must_equal path
76
+ end
34
77
 
35
- path = Pathname.new "xml_slideshow.xml"
36
- assert_equal path, slideshow.path(path) # Test setting the path
37
- assert_equal path, slideshow.path # Test getting the path
78
+ it "can have its start time set" do
79
+ time = Time.local 2007,5,3,1,0,0
80
+ @slideshow_default.start_time time
81
+ @slideshow_default.start_time.must_equal time
82
+ end
83
+
84
+ it "can be created with a start time" do
85
+ @slideshow.start_time.must_equal (Time.local 2009,8,4,0,0,0)
38
86
  end
39
87
 
40
- def test_wallpapers
41
- slideshow = GnomeWallpaperSlideshow.new
42
- wallpaper_one = GnomeWallpaperSlideshow::Wallpaper.new "test.jpg", 100, 5
43
- wallpaper_two = GnomeWallpaperSlideshow::Wallpaper.new "other.jpg", 500, 3
88
+ it "can be created with wallpapers" do
89
+ @slideshow.wallpapers.size.must_equal 2
90
+ @slideshow.wallpapers.must_equal [(GnomeWallpaperSlideshow::Wallpaper.new "test.jpg", 100, 5), (GnomeWallpaperSlideshow::Wallpaper.new "other.jpg", 500, 3)]
91
+ end
44
92
 
45
- assert_equal [], slideshow.wallpapers # Test handling of no wallpapers
93
+ it "can be created without wallpapers" do
94
+ @slideshow_default.wallpapers.must_be_empty
95
+ end
46
96
 
47
- # Test adding wallpapers
48
- slideshow.add_wallpaper wallpaper_one
49
- slideshow.add_wallpaper wallpaper_two
97
+ it "can have wallpapers added" do
98
+ wallpaper = GnomeWallpaperSlideshow::Wallpaper.new "test.jpg", 100, 5
99
+ @slideshow_default.add_wallpaper wallpaper
100
+ @slideshow_default.wallpapers.must_equal [(GnomeWallpaperSlideshow::Wallpaper.new "test.jpg", 100, 5)]
101
+ end
50
102
 
51
- assert_equal [wallpaper_one, wallpaper_two], slideshow.wallpapers
103
+ it "can have wallpapers removed" do
104
+ @slideshow.remove_wallpaper "test.jpg"
105
+ @slideshow.wallpapers.must_equal [(GnomeWallpaperSlideshow::Wallpaper.new "other.jpg", 500, 3)]
106
+ end
52
107
 
53
- # Test removing wallpapers
54
- slideshow.remove_wallpaper wallpaper_one.filename
108
+ it "can load an existing slideshow file" do
109
+ @slideshow_existing.path.must_equal (Pathname.new "real_slideshow.xml")
110
+ @slideshow_existing.start_time.must_equal (Time.local 2013,1,1,0,0,0)
111
+ @slideshow_existing.wallpapers.must_equal [(GnomeWallpaperSlideshow::Wallpaper.new "test.jpg", "100", "5"), (GnomeWallpaperSlideshow::Wallpaper.new "other.jpg", "500", "3")]
112
+ end
55
113
 
56
- assert_equal [wallpaper_two], slideshow.wallpapers
114
+ it "can write out an xml file" do
115
+ @slideshow.save_xml.must_equal "<?xml version=\"1.0\"?>
116
+ <background>
117
+ <starttime>
118
+ <year>2009</year>
119
+ <month>8</month>
120
+ <day>4</day>
121
+ <hour>0</hour>
122
+ <minute>0</minute>
123
+ <second>0</second>
124
+ </starttime>
125
+ <static>
126
+ <duration>100</duration>
127
+ <file>test.jpg</file>
128
+ </static>
129
+ <transition>
130
+ <duration>5</duration>
131
+ <from>test.jpg</from>
132
+ <to>other.jpg</to>
133
+ </transition>
134
+ <static>
135
+ <duration>500</duration>
136
+ <file>other.jpg</file>
137
+ </static>
138
+ <transition>
139
+ <duration>3</duration>
140
+ <from>other.jpg</from>
141
+ <to>test.jpg</to>
142
+ </transition>
143
+ </background>
144
+ "
57
145
  end
58
146
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gnome-wallpaper-slideshow
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.4'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-13 00:00:00.000000000 Z
12
+ date: 2012-01-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: nokogiri