Permalink
Browse files

added test, compat for writemime, dict comprehension

  • Loading branch information...
1 parent 166b85f commit c04a08ff76ab3261144ffcede5b33f51acab018f @wookay wookay committed Jun 30, 2016
Showing with 144 additions and 59 deletions.
  1. +13 −14 .travis.yml
  2. +1 −1 REQUIRE
  3. +34 −0 appveyor.yml
  4. +44 −19 src/IJulia/setup.jl
  5. +10 −2 src/IJulia/statedict.jl
  6. +0 −23 src/html_setup.jl
  7. +3 −0 test/REQUIRE
  8. +10 −0 test/runtests.jl
  9. +29 −0 test/widgets.jl
View
@@ -1,17 +1,16 @@
-language: cpp
-compiler:
- - clang
+language: julia
+os:
+ - linux
+ - osx
+julia:
+ - 0.4
+ - nightly
notifications:
email: false
-env:
- matrix:
- - JULIAVERSION="juliareleases"
- - JULIAVERSION="julianightlies"
-before_install:
- - sudo add-apt-repository ppa:staticfloat/julia-deps -y
- - sudo add-apt-repository ppa:staticfloat/${JULIAVERSION} -y
- - sudo apt-get update -qq -y
- - sudo apt-get install libpcre3-dev julia -y
script:
- - julia -e 'Pkg.init(); run(`ln -s $(pwd()) $(Pkg.dir("Interact"))`); Pkg.pin("Interact"); Pkg.resolve()'
- - julia -e 'using Interact; @assert isdefined(:Interact); @assert typeof(Interact) === Module'
+ - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
+ - julia -e 'Pkg.clone(pwd())'
+ - julia -e 'Pkg.test("Interact"; coverage=true)'
+after_success:
+ - julia --color=yes -e 'cd(Pkg.dir("Interact")); Pkg.add("Coverage"); using Coverage;
+ Coveralls.submit(Coveralls.process_folder())'
View
@@ -1,5 +1,5 @@
julia 0.4
JSON
-Compat 0.7.14
+Compat 0.8.0
Reactive 0.3
DataStructures 0.2.10
View
@@ -0,0 +1,34 @@
+environment:
+ matrix:
+ - JULIAVERSION: "julialang/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
+ - JULIAVERSION: "julialang/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
+ - JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe"
+ - JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe"
+
+branches:
+ only:
+ - master
+ - /release-.*/
+
+notifications:
+ - provider: Email
+ on_build_success: false
+ on_build_failure: false
+ on_build_status_changed: false
+
+install:
+# if there's a newer build queued for the same PR, cancel this one
+ - ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
+ https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
+ Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
+ throw "There are newer queued builds for this pull request, failing early." }
+# Download most recent Julia Windows binary
+ - ps: (new-object net.webclient).DownloadFile(
+ $("http://s3.amazonaws.com/"+$env:JULIAVERSION),
+ "C:\projects\julia-binary.exe")
+# Run installer silently, output to C:\projects\julia
+ - C:\projects\julia-binary.exe /S /D=C:\projects\julia
+
+build_script:
+ - C:\projects\julia\bin\julia -e "versioninfo(); Pkg.clone(pwd(), \"Interact\")"
+ - C:\projects\julia\bin\julia -e "Pkg.test(\"Interact\")"
View
@@ -1,6 +1,7 @@
using JSON
using Reactive
using Compat
+import Compat.String
import Interact: HTML, Widget, InputWidget, Slider, Button, Textarea, Textbox, ToggleButton, Options, Checkbox, Latex, Progress
@@ -26,12 +27,12 @@ import IJulia
import IJulia: metadata, display_dict
using IJulia.CommManager
import IJulia.CommManager: register_comm
-import Base: writemime, mimewritable
+import Base: show, mimewritable
const comms = Dict{Signal, Comm}()
function get_data_dict(value, mimetypes)
- dict = Dict{ASCIIString, ByteString}()
+ dict = Dict{Compat.String, Compat.String}()
for m in mimetypes
if mimewritable(m, value)
dict[m] = stringmime(m, value)
@@ -47,7 +48,7 @@ end
function init_comm(x::Signal)
if !haskey(comms, x)
- subscriptions = Dict{ASCIIString, Int}()
+ subscriptions = Dict{Compat.String, Int}()
function handle_subscriptions(msg)
if haskey(msg.content, "data")
action = get(msg.content["data"], "action", "")
@@ -92,36 +93,60 @@ mimewritable(m::MIME, s::Signal) =
mimewritable(m, s.value)
# fixes ambiguity warnings
-function writemime(io:: IO, m::MIME"text/plain", s::Signal)
- writemime(io, m, s.value)
+function Base.show(io::IO, m::MIME"text/plain", s::Signal)
+ Base.show(io, m, s.value)
end
-function writemime(io:: IO, m::MIME"text/csv", s::Signal)
- writemime(io, m, s.value)
+function Base.show(io::IO, m::MIME"text/csv", s::Signal)
+ Base.show(io, m, s.value)
end
-function writemime(io:: IO, m::MIME"text/tab-separated-values", s::Signal)
- writemime(io, m, s.value)
-end
-function writemime(io:: IO, m::MIME, s::Signal)
- writemime(io, m, s.value)
+function Base.show(io::IO, m::MIME"text/tab-separated-values", s::Signal)
+ Base.show(io, m, s.value)
end
-function writemime(io::IO, ::MIME{symbol("text/html")},
- w::InputWidget)
- create_view(w)
+function Base.show(io::IO, m::MIME, s::Signal)
+ Base.show(io, m, s.value)
end
-function writemime(io::IO, ::MIME{symbol("text/html")},
- w::Widget)
+function Base.show(io::IO, ::MIME"text/html", w::Widget)
create_view(w)
end
-function writemime{T<:Widget}(io::IO, ::MIME{symbol("text/html")},
- x::Signal{T})
+function Base.show{T<:Widget}(io::IO, ::MIME"text/html", x::Signal{T})
create_widget_signal(x)
end
+# Julia #14052 commit ae62bf0b813afbf32402874451e55d16de909bd4
+if VERSION < v"0.5-dev+4341"
+ import Base.writemime
+
+ function writemime(io::IO, m::MIME"text/plain", s::Signal)
+ writemime(io, m, s.value)
+ end
+
+ function writemime(io::IO, m::MIME"text/csv", s::Signal)
+ writemime(io, m, s.value)
+ end
+
+ function writemime(io::IO, m::MIME"text/tab-separated-values", s::Signal)
+ writemime(io, m, s.value)
+ end
+
+ function writemime(io::IO, m::MIME, s::Signal)
+ writemime(io, m, s.value)
+ end
+
+ function writemime(io::IO, ::MIME"text/html", w::Widget)
+ create_view(w)
+ end
+
+ function writemime{T<:Widget}(io::IO, ::MIME"text/html", x::Signal{T})
+ create_widget_signal(x)
+ end
+end
+
+
## This is for our own widgets.
function register_comm(comm::Comm{:InputWidget}, msg)
w_id = msg.content["data"]["widget_id"]
@@ -17,5 +17,13 @@ statedict(d::Options) =
:tooltips=>d.tooltips,
:_options_labels=>collect(keys(d.options)))
-statedict(w::Widget) =
- @compat Dict([f => getfield(w, f) for f in fieldnames(w)])
+function statedict(w::Widget)
+ # @compat Dict(f => getfield(w, f) for f in fieldnames(w))
+ # Julia issue #16561
+ # commit 879a7f75c7096aec4aa1b0c2a93a3ef432bb4cef
+ dict = Dict{Symbol,Any}()
+ for f in fieldnames(w)
+ dict[f] = getfield(w, f)
+ end
+ dict
+end
View
@@ -1,30 +1,7 @@
-import Base: writemime
-
-using JSON
-
const widgets_js = readstring(joinpath(dirname(Base.source_path()), "widgets.js"))
function init_widgets_js()
if displayable("text/html")
display("text/html", """<script charset="utf-8">$(widgets_js)</script>""")
end
end
-
-function writemime(io, ::MIME{symbol("text/html")}, w::InputWidget)
- wtype = typeof(w)
- while super(wtype) <: InputWidget
- wtype = super(wtype)
- end
-
- widgettype = string(typeof(w).name.name)
- inputtype = string(wtype.parameters[1].name.name)
-
- id = register_widget(w)
- el_id = "widget-$(id)"
-
- write(io, "<div class=\"input-widget ", lowercase(widgettype),
- "\" id=\"", el_id, "\"></div><script>(function(\$,W) {",
- "\$('#", el_id, "').empty().append((new W.",
- widgettype, "(\"", inputtype, "\",\"", id, "\",", JSON.json(statedict(w)), ")",
- ").elem);})(jQuery,InputWidgets)</script>")
-end
View
@@ -0,0 +1,3 @@
+julia 0.4
+Compat 0.8.0
+BaseTestNext
View
@@ -0,0 +1,10 @@
+if VERSION >= v"0.5-"
+ using Base.Test
+else
+ using BaseTestNext
+ const Test = BaseTestNext
+end
+
+@testset "widgets.jl" begin
+ include("widgets.jl")
+end
View
@@ -0,0 +1,29 @@
+if VERSION >= v"0.5-"
+ using Base.Test
+else
+ using BaseTestNext
+ const Test = BaseTestNext
+end
+
+using Interact
+import Interact: statedict, parse_msg
+import Reactive: value
+
+
+sliderWidget = slider(1:5)
+
+@test Dict(:range=>1:5,
+ :value=>3,
+ :readout_format=>"d",
+ :continuous_update=>true) == statedict(sliderWidget)
+@test 3 == value(signal(sliderWidget))
+@test 1 == parse_msg(sliderWidget, 1)
+@test 0 == parse_msg(sliderWidget, 0)
+
+
+checkboxWidget = checkbox(false)
+@test Dict(:value=>false) == statedict(checkboxWidget)
+@test false == value(signal(checkboxWidget))
+
+@test 1 == parse_msg(checkboxWidget, 1)
+@test 0 == parse_msg(checkboxWidget, 0)

0 comments on commit c04a08f

Please sign in to comment.