def test_item_equality(): it.assertTrue( Item(2, 1, [it.r1, it.r2, it.r3]) == Item(2, 1, [it.r1, it.r2, it.r3])) it.assertTrue( Item(2, 1, [it.r1, it.r2, it.r3]) != Item(2, 1, [ it.r1, it.r2, Region(Point(1, 1), Point(2, 2), 1, "region 4") ]))
def string_setup(): it.region = parser.region.text("This is/ a string/ with four/ regions") it.parsed_regions = [ Region(Point(0, 0), Point(7, 0), 7, "This is"), Region(Point(7, 0), Point(16, 0), 9, " a string"), Region(Point(16, 0), Point(26, 0), 10, " with four"), Region(Point(26, 0), Point(34, 0), 8, " regions"), ]
def test_d0_d1(): trial_1 = it.asc_header + "EFIX R 2000 2010 10 12 105 0" + it.asc_end trial_2 = """ MSG 20000 SYNCTIME MSG 20000 TRIALID E1I1D1 MSG 20001 REGION CHAR 1 1 A 10 100 20 110 MSG 20002 REGION CHAR 1 1 a 20 100 30 110 MSG 20003 REGION CHAR 1 1 a 30 100 40 110 MSG 20004 REGION CHAR 1 1 a 40 100 50 110 EFIX R 30000 30010 10 12 105 0 MSG 40000 TRIAL_RESULT 7 MSG 40001 TRIAL OK """ parsed_experiment = parser.asc.get_trials(trial_1 + trial_2, it.items) it.assertEqual(len(parsed_experiment), 1) it.assertEqual( parsed_experiment[0], Trial( 0, 10000, it.items["1"]["1"], [ Fixation(Point(0, 0), 0, 10, 0, it.items["1"]["1"].regions[0]) ], ), )
def test_region_equality(): it.assertTrue( Region(Point(0, 1), Point(10, 1), 1, "r") == Region(Point(0, 1), Point(10, 1), 1, "r") ) it.assertTrue( Region(Point(0, 1), Point(10, 1), 1, "r") != Region(Point(0, 1), Point(10, 2), 1, "r") )
def test_region_validation(): with it.assertRaises(ValueError): Region(Point(0, 1), Point(10, 0), 1, "invalid: y2 < y1") with it.assertRaises(ValueError): Region(Point(10, 1), Point(7, 1), 1, "invalid: x2 < x1") with it.assertRaises(ValueError): Region(Point(-1, 0), Point(1, 1), 1, "invalid: negative position") with it.assertRaises(ValueError): Region(Point(-1, 0), Point(1, 1), -1, "invalid: negative position")
def setup(): it.r1 = Region(Point(1, 1), Point(2, 2), 1, "region 1") it.r2 = Region(Point(1, 1), Point(2, 2), 1, "region 2") it.r3 = Region(Point(1, 1), Point(2, 2), 1, "region 3") it.fix1 = Fixation(Point(1, 2), 3, 4, 0, "region") it.fix2 = Fixation(Point(1, 2), 5, 6, 1, "region") it.fix3 = Fixation(Point(1, 3), 8, 9, 2, "region") it.item = Item(1, 1, [it.r1, it.r2, it.r3]) it.item2 = Item(2, 1, [it.r1, it.r3]) it.trial = Trial(1, 4, it.item, [it.fix1, it.fix2, it.fix3]) it.trial2 = Trial(2, 4, it.item2, [it.fix1, it.fix3]) it.experiment = Experiment("ex1", [it.trial, it.trial2], filename="ex1.da1")
def test_multifix_da1(): fixation = "EFIX R 2000 2010 10 12 105 0\nEFIX R 2010 2030 20 72 105 0" parsed_experiment = parser.asc.get_trials( it.asc_header + fixation + it.asc_end, it.items) it.assertEqual( parsed_experiment[0], Trial( 0, 10000, it.items["1"]["1"], [ Fixation(Point(0, 0), 0, 10, 0, it.items["1"]["1"].regions[0]), Fixation(Point(6, 0), 10, 30, 1, it.items["1"]["1"].regions[1]), ], ), )
def test_2_asc(): trial_1 = it.asc_header + "EFIX R 2000 2010 10 12 105 0" + it.asc_end trial_2 = """ MSG 20000 SYNCTIME MSG 20000 TRIALID E1I1D0 MSG 20001 REGION CHAR 1 1 T 10 100 20 110 MSG 20002 REGION CHAR 1 1 e 20 100 30 110 MSG 20003 REGION CHAR 1 1 s 30 100 40 110 MSG 20004 REGION CHAR 1 1 t 40 100 50 110 MSG 20005 REGION CHAR 1 1 50 100 60 110 MSG 20006 REGION CHAR 1 1 i 60 100 70 110 MSG 20007 REGION CHAR 1 1 t 70 100 80 110 MSG 20008 REGION CHAR 1 1 e 80 100 90 110 MSG 20009 REGION CHAR 1 1 m 90 100 100 110 EFIX R 30000 30010 10 12 105 0 MSG 40000 TRIAL_RESULT 7 MSG 40001 TRIAL OK """ parsed_experiment = parser.asc.get_trials(trial_1 + trial_2, it.items) it.assertEqual(len(parsed_experiment), 2) it.assertEqual( parsed_experiment[0], Trial( 0, 10000, it.items["1"]["1"], [ Fixation(Point(0, 0), 0, 10, 0, it.items["1"]["1"].regions[0]) ], ), ) it.assertEqual( parsed_experiment[1], Trial( 1, 20000, it.items["1"]["1"], [ Fixation(Point(0, 0), 0, 10, 0, it.items["1"]["1"].regions[0]) ], ), )
def test_asc(): fixation = "EFIX R 2000 2010 10 12 105 0" parsed_experiment = parser.asc.get_trials( it.asc_header + fixation + it.asc_end, it.items) it.assertEqual(len(parsed_experiment), 1) it.assertEqual( parsed_experiment[0], Trial( 0, 10000, it.items["1"]["1"], [ Fixation(Point(0, 0), 0, 10, 0, it.items["1"]["1"].regions[0]) ], ), )
def test_fix_before_synctime(): fixations = """ MSG 1000 TRIALID E1I1D0 MSG 1001 REGION CHAR 1 1 T 10 100 20 110 MSG 1002 REGION CHAR 1 1 e 20 100 30 110 MSG 1003 REGION CHAR 1 1 s 30 100 40 110 MSG 1004 REGION CHAR 1 1 t 40 100 50 110 MSG 1005 REGION CHAR 1 1 50 100 60 110 MSG 1006 REGION CHAR 1 1 i 60 100 70 110 MSG 1007 REGION CHAR 1 1 t 70 100 80 110 MSG 1008 REGION CHAR 1 1 e 80 100 90 110 MSG 1009 REGION CHAR 1 1 m 90 100 100 110 EFIX R 2000 2005 5 12 105 0 MSG 2001 SYNCTIME EFIX R 2005 2020 15 33 105 0 """ parsed_experiment = parser.asc.get_trials( fixations + it.asc_end, it.items, config.ASCParsingConfig({ "blink_max_dur": False, "blink_max_count": False, "max_saccade_dur": False, "fixation_min_cutoff": 10, }), ) it.assertEqual( parsed_experiment[0], Trial( 0, 8000, it.items["1"]["1"], [ Fixation(Point(2, 0), 0, 15, 0, it.items["1"]["1"].regions[0]) ], ), )
def test_first_fix_merge(): fixations = "EFIX R 2000 2005 5 12 105 0\nEFIX R 2005 2020 15 33 105 0" parsed_experiment = parser.asc.get_trials( it.asc_header + fixations + it.asc_end, it.items, config.ASCParsingConfig({ "blink_max_dur": False, "blink_max_count": False, "max_saccade_dur": False, "fixation_min_cutoff": 10, }), ) it.assertEqual( parsed_experiment[0], Trial( 0, 10000, it.items["1"]["1"], [ Fixation(Point(2, 0), 0, 20, 0, it.items["1"]["1"].regions[0]) ], ), )
def test_short_blinks(): fixation = "EFIX R 2000 2010 10 12 105 0\nEBLINK R 2010 2015 5" parsed_experiment = parser.asc.get_trials( it.asc_header + fixation + it.asc_end, it.items, config.ASCParsingConfig({ "blink_max_dur": 20, "blink_max_count": False, "max_saccade_dur": False, "fixation_min_cutoff": False, }), ) it.assertEqual( parsed_experiment[0], Trial( 0, 10000, it.items["1"]["1"], [ Fixation(Point(0, 0), 0, 10, 0, it.items["1"]["1"].regions[0]) ], ), )
def setup(): it.r1 = Region(Point(1, 1), Point(2, 2), 1, "region 1") it.r2 = Region(Point(1, 1), Point(2, 2), 1, "region 2") it.r3 = Region(Point(1, 1), Point(2, 2), 1, "region 3") it.fix1 = Fixation(Point(1, 2), 3, 4, 0, "region") it.fix2 = Fixation(Point(1, 2), 5, 6, 1, "region") it.fixations = [ Fixation(Point(1, 2), 10, 20, 0, "region"), Fixation(Point(2, 2), 30, 40, 1, "region"), Fixation(Point(3, 2), 50, 60, 2, "region"), Fixation(Point(4, 2), 70, 80, 3, "region", excluded=True), Fixation(Point(1, 2), 90, 100, 4, "region"), Fixation(Point(2, 2), 110, 120, 5, "region", excluded=True), Fixation(Point(3, 2), 130, 140, 6, "region", excluded=True), Fixation(Point(4, 2), 150, 160, 7, "region"), Fixation(Point(5, 2), 170, 180, 8, "region", excluded=True), ] it.item = Item(2, 1, [it.r1, it.r2, it.r3]) it.trial = Trial(1, 5, it.item, it.fixations) it.trial_include_fixations = Trial(1, 5, it.item, it.fixations, include_fixation=True) it.trial_include_saccades = Trial(1, 5, it.item, it.fixations, include_saccades=True) it.trial_include_both = Trial(1, 5, it.item, it.fixations, include_fixation=True, include_saccades=True)
def setup(): it.r1 = Region(Point(1, 1), Point(3, 1), 1, "region 1") it.r2 = Region(Point(3, 1), Point(8, 1), 1, "region 2") it.r3 = Region(Point(8, 1), Point(2, 2), 1, "region 3") it.r4 = Region(Point(1, 1), Point(3, 1), 1, "region 1") it.r5 = Region(Point(3, 1), Point(8, 1), 1, "region 2") it.r6 = Region(Point(8, 1), Point(2, 2), 1, "region 3") it.labeled_item = Item(1, 1, [it.r1, it.r2, it.r3], ["r1", "r2", "r3"]) it.unlabeled_item = Item(2, 1, [it.r4, it.r5, it.r6])
def test_region_string_file(): it.assertEqual( it.txt_items["1"]["1"], Item( "1", "1", [ Region(Point(0, 0), Point(17, 0), 17, "this is region 1 "), Region(Point(17, 0), Point(33, 0), 16, "this is region 2"), Region(Point(33, 0), Point(50, 0), 17, " this is region 3"), Region(Point(50, 0), Point(18, 1), 18, "this is a new line"), Region( Point(18, 1), Point(40, 1), 22, "this is another region" ), Region(Point(40, 1), Point(20, 2), 20, "this is a third line"), ], ), ) it.assertEqual( it.txt_items["1"]["2"], Item( "1", "2", [Region(Point(0, 0), Point(20, 0), 20, "item with one region")], ), ) it.assertEqual( it.txt_items["2"]["1"], Item( "2", "1", [ Region(Point(0, 0), Point(9, 0), 9, "item with"), Region(Point(9, 0), Point(19, 1), 19, "one region per line"), ], ), ) it.assertEqual( it.txt_items["2"]["2"], Item( "2", "2", [ Region(Point(0, 0), Point(8, 0), 8, "this is "), Region(Point(8, 0), Point(16, 0), 8, "an item "), Region(Point(16, 0), Point(20, 0), 4, "with"), Region(Point(20, 0), Point(12, 1), 12, "three lines "), Region(Point(12, 1), Point(22, 1), 10, "of regions"), Region(Point(22, 1), Point(21, 2), 21, "and multiple regions "), Region(Point(21, 2), Point(29, 2), 8, "per line"), ], ), ) it.assertEqual( it.txt_items["3"]["1"], Item( "3", "1", [ Region(Point(0, 0), Point(10, 1), 20, "this is an\nitem with "), Region( Point(10, 1), Point(46, 1), 36, "a new line in the middle of a region", ), ], ), )
def test_da1(): it.timdrop_fixations = [ Fixation( Point(-1, -1), 0, 170, 0, Region(Point(0, 0), Point(20, 0), label=0, number=0), ), Fixation( Point(7, 0), 195, 587, 1, Region(Point(0, 0), Point(20, 0), label=0, number=0), ), Fixation( Point(24, 0), 627, 841, 2, Region(Point(20, 0), Point(26, 0), label=1, number=1), ), Fixation( Point(46, 0), 892, 1157, 3, Region(Point(38, 0), Point(75, 0), label=4, number=4), ), Fixation( Point(58, 0), 1184, 1424, 4, Region(Point(38, 0), Point(75, 0), label=4, number=4), ), Fixation( Point(70, 0), 1452, 1779, 5, Region(Point(38, 0), Point(75, 0), label=4, number=4), ), ] it.trial1 = Trial(1, 1779, it.timdrop_items["286"]["2"], it.timdrop_fixations) it.assertEqual(it.timdrop_DA1.trials[("286", "2")], it.trial1)
def test_da1_robodoc(): it.robodoc_fixations = [ Fixation( Point(6, 0), 1241, 1410, 0, Region(Point(0, 0), Point(17, 0), label=0, number=0), ), Fixation( Point(4, 0), 1429, 1796, 1, Region(Point(0, 0), Point(17, 0), label=0, number=0), ), Fixation( Point(16, 0), 1822, 2223, 2, Region(Point(0, 0), Point(17, 0), label=0, number=0), ), Fixation( Point(6, 0), 2245, 2471, 3, Region(Point(0, 0), Point(17, 0), label=0, number=0), ), Fixation( Point(24, 0), 2504, 3232, 4, Region(Point(17, 0), Point(29, 0), label=1, number=1), ), Fixation( Point(32, 0), 3262, 3520, 5, Region(Point(29, 0), Point(40, 0), label=2, number=2), ), Fixation( Point(39, 0), 3552, 3894, 6, Region(Point(29, 0), Point(40, 0), label=2, number=2), ), Fixation( Point(44, 0), 3924, 4164, 7, Region(Point(40, 0), Point(52, 0), label=3, number=3), ), Fixation( Point(55, 0), 4189, 4671, 8, Region(Point(52, 0), Point(65, 0), label=4, number=4), ), Fixation( Point(49, 0), 4696, 4931, 9, Region(Point(40, 0), Point(52, 0), label=3, number=3), ), Fixation( Point(69, 0), 4959, 5250, 10, Region(Point(65, 0), Point(77, 0), label=5, number=5), ), Fixation( Point(65, 0), 5271, 5633, 11, Region(Point(65, 0), Point(77, 0), label=5, number=5), ), Fixation( Point(72, 0), 5656, 5885, 12, Region(Point(65, 0), Point(77, 0), label=5, number=5), ), Fixation( Point(81, 0), 5910, 6278, 13, Region(Point(77, 0), Point(95, 0), label=6, number=6), ), Fixation( Point(87, 0), 6300, 6625, 14, Region(Point(77, 0), Point(95, 0), label=6, number=6), ), Fixation( Point(81, 0), 6647, 6851, 15, Region(Point(77, 0), Point(95, 0), label=6, number=6), ), Fixation( Point(78, 0), 6873, 7231, 16, Region(Point(77, 0), Point(95, 0), label=6, number=6), ), Fixation( Point(87, 0), 7256, 7768, 17, Region(Point(77, 0), Point(95, 0), label=6, number=6), ), ] it.trial7 = Trial(7, 7792, it.robodoc_items["58"]["12"], it.robodoc_fixations) it.assertEqual(it.robodoc_DA1.trials[("58", "12")], it.trial7)
def setup_region(): it.dirname = os.path.dirname(os.path.realpath(__file__)) it.config = config.Configuration() it.config.region_fields.number = 1 it.config.region_fields.condition = 0 it.config.region_fields.boundaries_start = 3 it.config.region_fields.includes_y = True it.reg = parser.region.file( os.path.join(it.dirname, "testdata/robodocDA1.reg"), it.config) it.config.region_fields.number = 0 it.config.region_fields.condition = 1 it.config.region_fields.boundaries_start = 3 it.config.region_fields.includes_y = False it.cnt = parser.region.file( os.path.join(it.dirname, "testdata/timdropDA1.cnt"), it.config) it.reg_regions = [ Region(Point(0, 0), Point(11, 0)), Region(Point(11, 0), Point(21, 0)), Region(Point(21, 0), Point(34, 0)), Region(Point(34, 0), Point(45, 0)), Region(Point(45, 0), Point(61, 0)), Region(Point(61, 0), Point(73, 0)), Region(Point(73, 0), Point(92, 0)), ] it.reg_item = Item("57", "11", it.reg_regions) it.cnt_regions = [ Region(Point(0, 0), Point(15, 0)), Region(Point(15, 0), Point(19, 0)), Region(Point(19, 0), Point(25, 0)), Region(Point(25, 0), Point(28, 0)), Region(Point(28, 0), Point(47, 0)), ] it.cnt_item = Item("1", "1", it.cnt_regions)
def setup(): it.fix1 = Fixation(Point(1, 2), 3, 4, 0, "region") it.fix2 = Fixation(Point(1, 2), 5, 6, 1, "region")